CF178B2.Greedy Merchants
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The first input line contains two integers n and m , separated by a space, n is the number of cities, and m is the number of roads in the empire.
The following m lines contain pairs of integers ai , bi (1<=ai,bi<=n,ai=bi) , separated by a space — the numbers of cities connected by the i -th road. It is guaranteed that any two cities are connected by no more than one road and that there exists a path between any two cities in the Roman Empire.
The next line contains a single integer k — the number of merchants in the empire.
The following k lines contain pairs of integers si , li (1<=si,li<=n) , separated by a space, — si is the number of the city in which the warehouse of the i -th merchant is located, and li is the number of the city in which the shop of the i -th merchant is located.
The input limitations for getting 20 points are:
- 1<=n<=200
- 1<=m<=200
- 1<=k<=200
The input limitations for getting 50 points are:
- 1<=n<=2000
- 1<=m<=2000
- 1<=k<=2000
The input limitations for getting 100 points are:
- 1<=n<=105
- 1<=m<=105
- 1<=k<=105
输入格式
Print exactly k lines, the i -th line should contain a single integer di — the number of dinars that the i -th merchant paid.
输出格式
The given sample is illustrated in the figure below.
Let's describe the result for the first merchant. The merchant's warehouse is located in city 1 and his shop is in city 5 . Let us note that if either road, (1,2) or (2,3) is destroyed, there won't be any path between cities 1 and 5 anymore. If any other road is destroyed, the path will be preserved. That's why for the given merchant the answer is 2 .
输入输出样例
输入#1
7 8 1 2 2 3 3 4 4 5 5 6 5 7 3 5 4 7 4 1 5 2 4 2 6 4 7
输出#1
2 1 2 0
说明/提示
The given sample is illustrated in the figure below.
Let's describe the result for the first merchant. The merchant's warehouse is located in city 1 and his shop is in city 5 . Let us note that if either road, (1,2) or (2,3) is destroyed, there won't be any path between cities 1 and 5 anymore. If any other road is destroyed, the path will be preserved. That's why for the given merchant the answer is 2 .