#P13763. [CERC 2021] Airline

[CERC 2021] Airline

题目描述

An airline company offers regular flights involving nn different airports. Each flight links two airports directly (i.e. without stopping at any other airport) and allows travel in both directions. The flights are arranged such that for any choice of starting airport ss and destination airport tt, there exists exactly one sequence of flights between the two airports without visiting any airport more than once. The number of flights in this sequence is called the distance between ss and tt.

Were the airline to add another flight, say between airports xx and yy, it is possible that for some pairs (s,t)(s, t), another, shorter sequence of flights from ss to tt would form. The more pairs affected, the more promising the new connection between xx and yy is considered to be. The airline is asking you to help them evaluate several possible additions (x,y)(x, y) with respect to this criterion.

输入格式

An airline company offers regular flights involving nn different airports. Each flight links two airports directly (i.e. without stopping at any other airport) and allows travel in both directions. The flights are arranged such that for any choice of starting airport ss and destination airport tt, there exists exactly one sequence of flights between the two airports without visiting any airport more than once. The number of flights in this sequence is called the distance between ss and tt.

Were the airline to add another flight, say between airports xx and yy, it is possible that for some pairs (s,t)(s, t), another, shorter sequence of flights from ss to tt would form. The more pairs affected, the more promising the new connection between xx and yy is considered to be. The airline is asking you to help them evaluate several possible additions (x,y)(x, y) with respect to this criterion.

输出格式

Output qq lines; in the ii-th line, output the number of pairs (s,t)(s, t) such that 1s<tn1 \leq s < t \leq n and the distance between airports ss and tt would decrease if the original network of n1n - 1 flights were supplemented by a direct flight connection between the airports xix_i and yiy_i.

8 2
1 5
5 2
7 3
3 8
6 4
4 5
6 3
5 7
2 6
10
4

提示

Input limits

  • 2n1062 \leq n \leq 10^6
  • 1q1051 \leq q \leq 10^5
  • 1uin;1vin;uivi1 \leq u_i \leq n; 1 \leq v_i \leq n; u_i \neq v_i
  • 1xin;1yin;xiyi1 \leq x_i \leq n; 1 \leq y_i \leq n; x_i \neq y_i
  • i=1qdi107\sum_{i=1}^{q} d_i \leq 10^7, where did_i is the distance between xix_i and yiy_i in the original flight network.