TLE in TREDIFF

Amongst other things (e.g. passing v by value in dfs), you’re also making exactly the same mistake as this guy (and countless others in that thread).

Stamping out this CP anti-pattern is probably top of my if I ruled the world list :slight_smile:

2 Likes

I didn’t get the point :pensive: Would you explain me little more?

Try this test input; it won’t TLE, but it should give you a hint about what is going on (and what is causing your TLE):

5
6 3
10 2 5 6 5 6
1 2
2 3
2 4
1 5
5 6
5 6
3 5
1 4
6 3
10 2 5 6 5 6
1 2
2 3
2 4
1 5
5 6
5 6
3 5
1 4
6 3
10 2 5 6 5 6
1 2
2 3
2 4
1 5
5 6
5 6
3 5
1 4
6 3
10 2 5 6 5 6
1 2
2 3
2 4
1 5
5 6
5 6
3 5
1 4
6 3
10 2 5 6 5 6
1 2
2 3
2 4
1 5
5 6
5 6
3 5
1 4
6 3
2 Likes

Oh my mistake was not clearing edge vector ? Did I have made any other mistake?
N,Q<=1000 is for each TC or overall?

Yes. Or more fundamentally: this.

Passing v by value is another one.

The wording suggests “each TC”.

1 Like

How passing v by value is giving TLE?

https://www.codechef.com/viewsolution/33564974
After changes, but this is also giving tLE

You’re still passing v by value.

1 Like

Yeah, why passing by value giving TLE?
Now it turned into WA CodeChef: Practical coding for everyone

Passing by value copies the vector every time you pass it; passing by reference does not.

2 Likes

Oh but having globally vector v is giving WA :pensive:

I meant “pass v by reference”, not “make v global” XD

1 Like

In both case it is giving WA. CodeChef: Practical coding for everyone

Why are you only sometimes calling v.pop_back()?

2 Likes

Finally got it. Thanks a lot!!

1 Like

I dislike your hate for global variables, they make function headers much less ugly

3 Likes

I saw the editorial and designed my code in that way but i am getting runtime error when i submit my code.
It would be great help if you could tell e why its giving SIGSEV.
https://www.codechef.com/viewsolution/33577600
Thanks again.

It’s quite a bad idea to return in the middle of a test case, especially before reading in all the input

Ya, my bad i shared the wrong solution. This is giving SIGSEV despite the fact of not returning and doing everything else the same way.
https://www.codechef.com/viewsolution/33585543
It would be nice if you could point out what us going wrong for a beginner like me.
Thanks.

Wait, why would you comment out line 11