Ellen is a student at RHHS who is trying to navigate her way through the school to get to her classes. She knows that most halls are going to be blocked off by large groups of aimless students, so she has devised a map of the school which only includes hallways she knows will be open. In particular, the school can be represented as a collection of
Because Ellen is travelling around the school a lot, she wants to know how far it is between different locations in the school, so she can plan how long it will take to walk between them.
To help her with this, you will be given
Input Specification
The first line will contain
The next
The next line will contain
The next
For test cases worth 20 of 100 points,
For test cases worth an additional 20 points,
Output Specification
For each query, output a single integer on its own line which is the distance between the two classrooms in the query.
Sample Input
5
0 1 3
0 3 2
0 4 7
1 2 5
4
2 0
1 4
3 1
3 4
Sample Output
8
10
5
9
Comments
are hallways bidirectional?
This comment is hidden due to too much negative feedback. Show it anyway.
was that not an intended solution?
or did they just not want data to be huge?
This comment is hidden due to too much negative feedback. Show it anyway.
Seriously? I was halfway through solving this problem when you lowered the points. If anything, just tighten the time limit if you think it is too easy.
That's up to the problemsetter as the admins would be encroaching on their "creative license" by changing the time limit.