#SRD0000117. DeMen100ns và thành phố (DeMen100ns and Cities)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 cities labeled from to and 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 .
- Each of the following lines contains an unordered edge .
Output
Print one integer: the number of unordered triangles.
Subtasks
-
Subtask 1 (10 points): , , ; , ; a simple undirected graph, possibly disconnected.
-
Subtask 2 (20 points): , , ; , ; a simple undirected graph, possibly disconnected.
-
Subtask 3 (30 points): , , ; , ; a simple undirected graph, possibly disconnected.
-
Subtask 4 (40 points): , , ; , ; 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 ; every three vertices form a triangle, giving triangles.