## RTE '16 S3 - School Traversal

View as PDF

Points: 7 (partial)
Time limit: 1.8s
Memory limit: 256M

Author:
Problem type

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 classrooms numbered to with hallways between them. It is guaranteed that these hallways will never form a loop.

Because Ellen is travelling around the school a lot, she wants to know how far it is between various 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 queries; for each one you must determine the distance between the two given classrooms.

#### Input Specification

The first line will contain , the number of classrooms.

The next lines will contain three space-separated integers, , , , , indicating that there is a hallway between classrooms and with length .

The next line will contain , the number of queries to be answered.

The next lines will contain two space-separated integers, and , representing a query that asks the distance between classrooms and .

For test cases worth 20 of 100 points, and .

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

• Roronoa_Zoro1540  commented on Jan. 28, 2018, 7:02 p.m.

are hallways bidirectional?

• Kirito  commented on June 8, 2017, 1:15 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• imaxblue  commented on June 10, 2017, 9:19 p.m.

was that not an intended solution?

or did they just not want data to be huge?

• Kirito  commented on June 10, 2017, 9:27 p.m.

Likely the latter, as their solution was

• root  commented on June 8, 2017, 8:33 p.m.

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.

• P234rex  commented on June 10, 2017, 11:03 p.m.

That's up to the problemsetter as the admins would be encroaching on their "creative license" by changing the time limit.