#P15957. [ICPC 2018 Jakarta R] Go Make It Complete
[ICPC 2018 Jakarta R] Go Make It Complete
题目描述
Andi has a network with machines and links; each link connects exactly two different machines. Due to some circumstances, Andi has to make his network “complete”, i.e. every machine is directly linked to every other machine. This means Andy has to add a new link between any pair of machines which are not already directly linked.
In order to accomplish his goal, Andi outsources the work to a company, Go. Go accepts any work order on a network with a requested integer , i.e. . The way Go works: First, it creates a list containing all pair of machines which are not yet directly linked. Then, Go evaluates each pair of machines from and create a new link between them if . Note that is the degree of machine , i.e. the number of links has at the time of evaluation. Similarly, is for machine .
The problem with Go’s procedure is it evaluates each pair of machines in the order appeared in . For example, let be a network with machines (machine and ) and links; the links are . The degree of each machine before a work order is requested is: , , , , or simply can be written as . Let say a work order with is requested ().
Consider these two lists:
-
.
- × Evaluate and don’t create a new link since . The degree is still .
- ✓ Evaluate and create a new link since . The degree becomes .
- ✓ Evaluate and create a new link since . The degree becomes .
The final result is a network with links, which is not complete as it misses the link.
-
.
- ✓ Evaluate and create a new link since . The degree becomes .
- ✓ Evaluate and create a new link since . The degree becomes .
- ✓ Evaluate and create a new link since . The degree becomes .
The final result is a network with links and complete.
As we can see, produces a complete network, while is not.
Ordering a work to Go can be very expensive with lower , thus, Andi has to make as high as possible while maintaining the possibility that a complete network can be achieved with . In other words, Andi wants the highest such that there exists such that can produce a complete network, and for any (), there is no valid for which can produce a complete network. Your task in this problem is to find such .
输入格式
Input begins with a line containing two integers: (; ) representing the number of machines and the number existing links, respectively. The machines are numbered from to . The next lines, each contains two integers: () representing an existing link connecting machine and . You are guaranteed that each pair will appear at most once in the input.
输出格式
Output contains an integer in a line, as requested.
4 3
1 2
2 3
3 4
3
5 0
0
5 2
1 2
3 4
2
提示
Explanation for the sample input/output #2
Andi’s network has no link at all at the beginning. To make his network complete, Andi has to order .