#5942. [CERC 2021] Airline

[CERC 2021] Airline

[CERC 2021] Airline

题目描述

An airline company offers regular flights involving $n$ 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 $s$ and destination airport $t$, 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 $s$ and $t$.

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 $n$ 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 $s$ and destination airport $t$, 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 $s$ and $t$.

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 $q$ lines; in the $i$-th line, output the number of pairs $(s, t)$ such that $1 \leq s
8 2
1 5
5 2
7 3
3 8
6 4
4 5
6 3
5 7
2 6
10
4

提示

### Input limits
  • 2≤n≤1062 \leq n \leq 10^6
  • 1≤q≤1051 \leq q \leq 10^5
  • 1≤ui≤n;1≤vi≤n;ui≠vi1 \leq u_i \leq n; 1 \leq v_i \leq n; u_i \neq v_i
  • 1≤xi≤n;1≤yi≤n;xi≠yi1 \leq x_i \leq n; 1 \leq y_i \leq n; x_i \neq y_i
  • ∑i=1qdi≤107\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. 标签: P13763|2021|树形 DP|树的遍历|ICPC|CERC

来源

P13763|[CERC 2021] Airline