luogu#P4320. 道路相遇
道路相遇
Background
Description
In country H, Xiao w decides to travel from city to city . However, for various reasons, Xiao c is not in city , but Xiao c decides to meet Xiao w somewhere along the way.
Because of the road network in country H, the route Xiao w takes from city to city is not fixed. To plan time reasonably, Xiao c wants to know how many cities Xiao w will definitely pass through on all possible routes from city to city . In particular, and must also be counted, which means the answer is never less than .
For various reasons, Xiao c does not know Xiao w’s exact start and end cities, but Xiao c knows there are only possible pairs of start and end cities. For each of these possibilities, Xiao c wants to know the number of cities that Xiao w will definitely pass through.
All edges in country H are undirected. Between any two cities, there is at most one direct road. There is no road that connects a city to itself.
At all times, the graph is connected.
Output Format
Output lines, each containing a single positive integer.
5 6
1 2
1 3
2 3
3 4
4 5
3 5
1
1 5
3
Hint
From city to city there are possible routes:
It can be seen that Xiao w will always pass through cities , so the answer is .
You may assume Xiao w will not visit the same city twice. Of course, even if you think revisiting cities is allowed, it does not affect the answer.
Subtask 1: 15 points, .
Subtask 2: 15 points, .
Subtask 3: 20 points, .
Subtask 4: 20 points, .
Subtask 5: 30 points, .
Constraints: For all testdata: $1 \leq n \leq 5 \times 10^5, 1 \leq q \leq 5 \times 10^5, 1 \leq m \leq \min(\frac{n(n-1)}{2}, 10^6)$.
Translated by ChatGPT 5