#P1051F. The Shortest Statement
The Shortest Statement
No submission language available for this problem.
Description
You are given a weighed undirected connected graph, consisting of vertices and edges.
You should answer queries, the -th query is to find the shortest distance between vertices and .
The first line contains two integers and — the number of vertices and edges in the graph.
Next lines contain the edges: the -th edge is a triple of integers . This triple means that there is an edge between vertices and of weight . It is guaranteed that graph contains no self-loops and multiple edges.
The next line contains a single integer — the number of queries.
Each of the next lines contains two integers and — descriptions of the queries.
Pay attention to the restriction .
Print lines.
The -th line should contain the answer to the -th query — the shortest distance between vertices and .
Input
The first line contains two integers and — the number of vertices and edges in the graph.
Next lines contain the edges: the -th edge is a triple of integers . This triple means that there is an edge between vertices and of weight . It is guaranteed that graph contains no self-loops and multiple edges.
The next line contains a single integer — the number of queries.
Each of the next lines contains two integers and — descriptions of the queries.
Pay attention to the restriction .
Output
Print lines.
The -th line should contain the answer to the -th query — the shortest distance between vertices and .