Graf has a graph, a graph with
Input Specification
The first line will have space-separated
The next
Output Specification
Output
Sample Input 1
Copy
6 7 1
1 2
2 3
1 4
2 5
4 6
3 4
2 6
Sample Output 1
Copy
3
5
3
4
2
3
Sample Input 2
Copy
4 6 1
1 2
1 3
1 4
2 3
2 4
3 4
Sample Output 2
Copy
4
4
4
4
Comments
I assumed this would essentially be an all pairs shortest path preprocessing step but it appears that is too slow. Any hints on the type of algorithm to look into for this? A tree reroot with a general graph exploration to establish search tree depth first seemed like a decent idea but I can't see how you can reroot with a graph vs a tree.
Is this question solvable in python?