I am getting MLE for this code https://codeforces.net/contest/1774/submission/186717963 Please Anyone Can help?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
I am getting MLE for this code https://codeforces.net/contest/1774/submission/186717963 Please Anyone Can help?
Name |
---|
Hey man, i solved ur memory problem with the following submission: https://codeforces.net/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://codeforces.net/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 :)