I am getting MLE for this code https://mirror.codeforces.com/contest/1774/submission/186717963 Please Anyone Can help?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3741 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3489 |
7 | Radewoosh | 3483 |
8 | Kevin114514 | 3443 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 158 |
5 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | djm03178 | 155 |
9 | TheScrasse | 154 |
10 | Dominater069 | 153 |
I am getting MLE for this code https://mirror.codeforces.com/contest/1774/submission/186717963 Please Anyone Can help?
Name |
---|
Hey man, i solved ur memory problem with the following submission: https://mirror.codeforces.com/contest/1774/submission/186734301
However, I got a time limit exceeded on the next test (22). Do u think u could give me a time complexity analysis for ur code to see what is the problem?
for my code the time complexity was O(n); where n is number of nodes
can u double check this please because my changes have not affected anything in your code but it is giving time limit exceeded on testcase 22.
The one thing more i have done is predefining the size of curr vector so to avoid mutliple times reallocation of size of the vector
Now i gets accepted by passing the visited vector by reference... !!
Thanks @TheOpChicken123 for pointing out.
https://mirror.codeforces.com/contest/1774/submission/186738592
Here is the revised code Link
alright man, good job
Pass the reference for
visted
andcurr
vectors and make the necessary changes inupdate()
andDFS()
functions.This is ACCEPTED submission of your code.
In
update()
you are not changing anything incurr
vector, so better pass its reference, which will be faster [ O(1) compared to your O(N) passing] and also reduces memory usage in recursive calls.In
DFS()
same thing.visited
andcurr
you can pass the reference. But one change is required forcurr
. As after every recursive function your lastly added element should be removed, add one extracurr.pop_back()
at the end ofDFS()
Hope you got it right :)