#P15957. [ICPC 2018 Jakarta R] Go Make It Complete

[ICPC 2018 Jakarta R] Go Make It Complete

题目描述

Andi has a network GG with NN machines and MM 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 GG with a requested integer kk, i.e. go(G,k)go(G, k). The way Go works: First, it creates a list LL containing all pair of machines which are not yet directly linked. Then, Go evaluates each pair of machines (a,b)(a, b) from LL and create a new link between them if δa+δbk\delta_a + \delta_b \geq k. Note that δa\delta_a is the degree of machine aa, i.e. the number of links aa has at the time of evaluation. Similarly, δb\delta_b is for machine bb.

The problem with Go’s procedure is it evaluates each pair of machines in the order appeared in LL. For example, let GG be a network with N=4N = 4 machines (machine 1,2,3,1, 2, 3, and 44) and M=3M = 3 links; the links are {(1,2),(2,3),(3,4)}\{(1, 2), (2, 3), (3, 4)\}. The degree of each machine before a work order is requested is: δ1=1\delta_1 = 1, δ2=2\delta_2 = 2, δ3=2\delta_3 = 2, δ4=1\delta_4 = 1, or simply can be written as [1,2,2,1][1, 2, 2, 1]. Let say a work order with k=3k = 3 is requested (go(G,3)go(G, 3)).

Consider these two lists:

  • L1=((1,4),(1,3),(2,4))L_1 = ((1, 4), (1, 3), (2, 4)).

    • × Evaluate (1,4)(1, 4) and don’t create a new link since δ1+δ4=1+1=2\delta_1 + \delta_4 = 1 + 1 = 2. The degree is still [1,2,2,1][1, 2, 2, 1].
    • ✓ Evaluate (1,3)(1, 3) and create a new link since δ1+δ3=1+2=3\delta_1 + \delta_3 = 1 + 2 = 3. The degree becomes [2,2,3,1][2, 2, 3, 1].
    • ✓ Evaluate (2,4)(2, 4) and create a new link since δ2+δ4=2+1=3\delta_2 + \delta_4 = 2 + 1 = 3. The degree becomes [2,3,3,2][2, 3, 3, 2].

    The final result is a network with 55 links, which is not complete as it misses the (1,4)(1, 4) link.

  • L2=((2,4),(1,3),(1,4))L_2 = ((2, 4), (1, 3), (1, 4)).

    • ✓ Evaluate (2,4)(2, 4) and create a new link since δ2+δ4=2+1=3\delta_2 + \delta_4 = 2 + 1 = 3. The degree becomes [1,3,2,2][1, 3, 2, 2].
    • ✓ Evaluate (1,3)(1, 3) and create a new link since δ1+δ3=1+2=3\delta_1 + \delta_3 = 1 + 2 = 3. The degree becomes [2,3,3,2][2, 3, 3, 2].
    • ✓ Evaluate (1,4)(1, 4) and create a new link since δ1+δ4=2+2=4\delta_1 + \delta_4 = 2 + 2 = 4. The degree becomes [3,3,3,3][3, 3, 3, 3].

    The final result is a network with 66 links and complete.

As we can see, L2L_2 produces a complete network, while L1L_1 is not.

Ordering a work to Go can be very expensive with lower kk, thus, Andi has to make kk as high as possible while maintaining the possibility that a complete network can be achieved with kk. In other words, Andi wants the highest kk such that there exists LL such that go(G,k)go(G, k) can produce a complete network, and for any jj (j>kj > k), there is no valid LL for go(G,j)go(G, j) which can produce a complete network. Your task in this problem is to find such kk.

输入格式

Input begins with a line containing two integers: NN MM (2N5002 \leq N \leq 500; 0M<N×(N1)20 \leq M < \frac{N \times (N-1)}{2}) representing the number of machines and the number existing links, respectively. The machines are numbered from 11 to NN. The next MM lines, each contains two integers: aia_i bib_i (1ai<biN1 \leq a_i < b_i \leq N) representing an existing link connecting machine aia_i and bib_i. You are guaranteed that each pair (ai,bi)(a_i, b_i) will appear at most once in the input.

输出格式

Output contains an integer kk 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 go(G,0)go(G, 0).