PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000117. DeMen100ns và thành phố (DeMen100ns and Cities)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

DeMen100ns và thành phố (DeMen100ns and Cities)

DeMen100ns and Cities

Source: VNOJ

Version: Phuoc Hung OJ Extended

Problem Statement

DeMen100ns manages a road network with nn cities labeled from 11 to nn and mm undirected roads.

Count the number of choices of three distinct cities such that every pair among them is connected by a direct road. Equivalently, count the triangles in the undirected graph.

Each triangle is counted once, regardless of the ordering of its three vertices. The input has no self-loops and no multiple edges; the graph need not be connected.

Input

  • The first line contains n,mn,m.
  • Each of the following mm lines contains an unordered edge u,vu,v.

Output

Print one integer: the number of unordered triangles.

Subtasks

  • Subtask 1 (10 points): 2≤n≤302\le n\le30, 1≤m≤1001\le m\le100, m≤(n2)m\le\binom n2; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; a simple undirected graph, possibly disconnected.

  • Subtask 2 (20 points): 2≤n≤1 0002\le n\le1\,000, 1≤m≤2 0001\le m\le2\,000, m≤(n2)m\le\binom n2; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; a simple undirected graph, possibly disconnected.

  • Subtask 3 (30 points): 2≤n≤20 0002\le n\le20\,000, 1≤m≤40 0001\le m\le40\,000, m≤(n2)m\le\binom n2; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; a simple undirected graph, possibly disconnected.

  • Subtask 4 (40 points): 2≤n≤1052\le n\le10^5, 1≤m≤2⋅1051\le m\le2\cdot10^5, m≤(n2)m\le\binom n2; 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; a simple undirected graph, possibly disconnected.

Examples

Example 1

Input

4 6
1 2
1 3
1 4
2 3
2 4
3 4

Output

4

Explanation

This is K4K_4; every three vertices form a triangle, giving (43)=4\binom43=4 triangles.