#P4630. [APIO2018] 铁人两项
[APIO2018] 铁人两项
Description
Bit Town’s road network consists of intersections connected by bidirectional roads.
Recently, Bit Town obtained the right to host a triathlon championship. The race has two stages: contestants first complete a long-distance running stage, and then ride a bicycle to complete the second stage.
The race route must be planned as follows:
- First, choose three pairwise distinct intersections , , and , as the start point, the transition point (after reaching this point during the running stage, athletes ride a bicycle to the finish), and the finish point.
- Choose a path that starts from , passes through , and finally reaches . For safety reasons, the chosen path visits each intersection at most once.
Before planning the route, the mayor wants you to help compute how many different ways there are to choose , , and , such that in step 2 there is at least one path that satisfies the requirement.
Input Format
The first line contains two integers and , representing the number of intersections and the number of bidirectional roads.
The next lines each contain two integers , indicating that there is a bidirectional road directly connecting intersections and (, ).
It is guaranteed that any two intersections are directly connected by at most one bidirectional road.
Output Format
Output one line containing one integer, the number of different ways to choose , , and that satisfy the requirement.
4 3
1 2
2 3
3 4
8
4 4
1 2
2 3
3 4
4 2
14
Hint
Hint
In the first sample, there are the following different choices of :
- $(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4), (3, 2, 1)$;
- .
In the second sample, there are the following different choices of :
- $(1, 2, 3), (1, 2, 4), (1, 3, 4), (1, 4, 3), (2, 3, 4)$;
- $(2, 4, 3), (3, 2, 1), (3, 2, 4), (3, 4, 1), (3, 4, 2)$;
- .
Subtasks
- Subtask 1 (points: ): , .
- Subtask 2 (points: ): , .
- Subtask 3 (points: ): , each intersection is an endpoint of at most two bidirectional roads.
- Subtask 4 (points: ): , there are no cycles in the road network (a cycle means that there exists a sequence of intersections of length (), , where all intersection labels in the sequence are pairwise distinct, and for from to there is a bidirectional road directly connecting and , and there is also a bidirectional road directly connecting and ).
- Subtask 5 (points: ): , there are no cycles in the road network.
- Subtask 6 (points: ): , each intersection belongs to at most one cycle.
- Subtask 7 (points: ): , each intersection belongs to at most one cycle.
- Subtask 8 (points: ): , .
- Subtask 9 (points: ): , .
Translated by ChatGPT 5
京公网安备 11011102002149号