#P4630. [APIO2018] 铁人两项

[APIO2018] 铁人两项

Description

Bit Town’s road network consists of nn intersections connected by mm 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:

  1. First, choose three pairwise distinct intersections ss, cc, and ff, 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.
  2. Choose a path that starts from ss, passes through cc, and finally reaches ff. 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 ss, cc, and ff, such that in step 2 there is at least one path that satisfies the requirement.

Input Format

The first line contains two integers nn and mm, representing the number of intersections and the number of bidirectional roads.

The next mm lines each contain two integers vi,uiv_i, u_i, indicating that there is a bidirectional road directly connecting intersections viv_i and uiu_i (1vi,uin1 \le v_i, u_i \le n, viuiv_i \neq u_i).

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 ss, cc, and ff 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 88 different choices of (s,c,f)(s, c, f):

  • $(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4), (3, 2, 1)$;
  • (4,2,1),(4,3,1),(4,3,2)(4, 2, 1), (4, 3, 1), (4, 3, 2).

In the second sample, there are the following 1414 different choices of (s,c,f)(s, c, f):

  • $(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)$;
  • (4,2,1),(4,2,3),(4,3,1),(4,3,2)(4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2).

Subtasks

  • Subtask 1 (points: 55): n10n \leq 10, m100m \leq 100.
  • Subtask 2 (points: 1111): n50n \leq 50, m100m \leq 100.
  • Subtask 3 (points: 88): n100000n \leq 100000, each intersection is an endpoint of at most two bidirectional roads.
  • Subtask 4 (points: 1010): n1000n \leq 1000, there are no cycles in the road network (a cycle means that there exists a sequence of intersections of length kk (k3k \ge 3), v1,v2,,vkv_1, v_2, \ldots, v_k, where all intersection labels in the sequence are pairwise distinct, and for ii from 11 to k1k - 1 there is a bidirectional road directly connecting viv_i and vi+1v_{i+1}, and there is also a bidirectional road directly connecting vkv_k and v1v_1).
  • Subtask 5 (points: 1313): n100000n \leq 100000, there are no cycles in the road network.
  • Subtask 6 (points: 1515): n1000n \leq 1000, each intersection belongs to at most one cycle.
  • Subtask 7 (points: 2020): n100000n \leq 100000, each intersection belongs to at most one cycle.
  • Subtask 8 (points: 88): n1000n \leq 1000, m2000m \leq 2000.
  • Subtask 9 (points: 1010): n100000n \leq 100000, m200000m \leq 200000.

Translated by ChatGPT 5