atcoder#ABC292E. [ABC292E] Transitivity
[ABC292E] Transitivity
Score : points
Problem Statement
You are given a simple directed graph with vertices numbered to and edges numbered to . Edge is a directed edge from vertex to vertex .
You may perform the following operation zero or more times.
- Choose distinct vertices and such that there is no directed edge from vertex to vertex , and add a directed edge from vertex to vertex .
Find the minimum number of times you need to perform the operation to make the graph satisfy the following condition.
- For every triple of distinct vertices , , and , if there are directed edges from vertex to vertex and from vertex to vertex , there is also a directed edge from vertex to vertex .
Constraints
- if .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
4 3
2 4
3 1
4 3
3
Initially, the condition is not satisfied because, for instance, for vertices , , and , there are directed edges from vertex to vertex and from vertex to vertex , but not from vertex to vertex .
You can make the graph satisfy the condition by adding the following three directed edges:
- one from vertex to vertex ,
- one from vertex to vertex , and
- one from vertex to vertex .
On the other hand, the condition cannot be satisfied by adding two or fewer edges, so the answer is .
292 0
0
5 8
1 2
2 1
1 3
3 1
1 4
4 1
1 5
5 1
12