I don't think this TLE is possible ...

Revision en2, by yosako, 2021-10-30 08:50:55

Oh hi Codeforces. I'm doing problem Longest Flight Route. At first I'm like "hum ... directed graph but with no circle, gotta find the longest path from 1 to n using normal BFS and I'm gonna be find ...". So it turned out that I didn't get AC because somehow I got TLE verdict on 2 test cases ... I checked the runtime of other test and saw that longest runtime for other test that got AC is like 0.09 sec so it must my algorithm's fault. I did some more check and found that something has caused my BFS to run like forever. However, it's not possible I think. My solution is just the reversed version of normal BFS : with current node u and it's child v, I check if (d[v] < d[u]+1) then update d[v], push v in the queue and I'm done (Oh sorry, I should have mention that d[i] is the longest path from 1 to i). This graph is guaranteed to have no circle, so how the heck did my code got 2 TLE

Here is my code ...

Pls leave some of your thought about this problem and what should I do to fix my code ... Can't see why BFS run forever.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English yosako 2021-10-30 08:50:55 4 Tiny change: '\n d[1] = 1;\n q.push' -> '\n d[1] = 0;\n q.push'
en1 English yosako 2021-10-30 08:14:00 2058 Initial revision (published)