2000 Canadian Computing Competition, Stage 2
Day 2, Problem 1: Packet RoutingThe date is October 29th, 1969. Today, scientists at UCLA made history by exchanging data between two computers over a network. The transmission wasn't very spectacular: only the first two letters of the word "login" were received before the system crashed. Nevertheless, the researchers are beginning to design larger computer networks and they need your help.
A computer network is a collection of N (2 ≤ N ≤ 100) computers and W wires. The computers are identified by the numbers 1, 2, ..., N. Each wire connects exactly two computers, allowing packets of data to flow in both directions between the computers. The wires are placed so that it is possible to send packets (directly or indirectly by passing through other computers) between every pair of computers. In fact, the placement of the wires has been optimized so that there is exactly one path between every pair of computers. If the packet travels along several wires to get from the source computer to the destination computer, the time needed for the packet to travel along this path is the sum of the times required for the packet to travel along each individual wire. You are to write a program that computes the amount of time needed for a packet to travel between a given pair of distinct computers.
InputThe first line of the input file contains the three positive integers N, W, P.
For each wire, a line follows giving the identification numbers of the two computers connected by the wire, and an integer between 1 and 500 giving the time required for a packet to travel along this wire.
P (1 ≤ P ≤ 10000) is the number of packets which need to be sent. For each packet, a line follows giving the identification numbers of the packet's source and destination computers.
OutputFor each packet, find the route through the network which will allow the packet to travel from the source computer to the destination computer. Output the travel time of this route on a single line.
3 2 3 1 2 100 2 3 150 2 1 2 3 1 3
100 150 250
Point Value: 10
Time Limit: 2.00s
Memory Limit: 16M
Added: Apr 19, 2009
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3