above, Polycarp might have made the accompanying voyages (not every conceivable choice): 2→5→1→2→5; 3→6→2; 1→3→6→2→5.
Correct answer will be upvoted else Multiple Downvoted. Computer science.
above, Polycarp might have made the accompanying voyages (not every conceivable choice):
2→5→1→2→5;
3→6→2;
1→3→6→2→5.
Polycarp needs for each beginning city I to discover how close he can get to the capital. All the more officially: he needs to track down the insignificant worth of dj that Polycarp can get from the city I to the city j as indicated by the standards portrayed previously.
Input
The primary line contains one integer t (1≤t≤104) — the number of experiments. Then, at that point, t experiments follow.
Each experiment is gone before by a vacant line.
The main line of each experiment contains two integers n (2≤n≤2⋅105) and m (1≤m≤2⋅105) — number of urban areas and streets, individually.
This is trailed by m lines portraying the streets. Every street is characterized by two integers u and v (1≤u,v≤n,u≠v) — the numbers of urban areas associated by a single direction street.
It is ensured that the amounts of n and m over all experiments don't surpass 2⋅105.
It is ensured that for each pair of various urban areas (u,v) there is all things considered one street from u to v (however a couple of streets from u to v and from v to u — is substantial).
It is ensured that there is a way from the funding to all urban communities.
Output
For each experiment, on a different line output n numbers, the I-th of which is equivalent to the base conceivable separation from the money to the city where Polycarp finished his excursion.
Step by step
Solved in 4 steps