#P7157. 「dWoi R1」Physics Problem
「dWoi R1」Physics Problem
Description
There are states, numbered from to . Among these states, there are kinds of transition relations. The -th transition relation is described as follows: state and state can be converted into each other. When there is no direct transition relation between two states but there is an indirect transition relation, then there is a "升降华" relation between these two states.
Find how many "升降华" relations there are.
Wang Ma cannot solve very hard physics problems, so it is guaranteed that one state can be converted to any other state through direct or indirect transitions.
Input Format
The first line contains two integers , representing the number of states and the number of transition relations.
In the next lines, each line contains two integers , meaning there is a transition relation between these two states.
Output Format
Output one integer in one line, representing how many "升降华" relations there are.
3 2
1 2
2 3
1
Hint
Explanation for Sample 1
There are states in total, numbered . There is a transition relation between state and state , and between state and state . There is no direct transition relation between state and state , but they can be converted using state as a bridge, so there is a "升降华" relation between state and state . There is only this one "升降华" relation, so output .
Constraints
This problem uses bundled tests.
- Subtask 1 (5 pts): .
- Subtask 2 (10 pts): , .
- Subtask 3 (10 pts): , .
- Subtask 4 (25 pts): .
- Subtask 5 (50 pts): no special restrictions.
For of the testdata, , .
It is guaranteed that , and there do not exist and .
This sentence can also be understood as: no multiple edges and no self-loops.
Hint
Note that for the following case (a - b means can be converted into and can be converted into ):
1 - 2
2 - 3
1 - 3
State and state are considered to have a direct transition relation, i.e. the transition relation uses the "shortest path".
Translated by ChatGPT 5
京公网安备 11011102002149号