#P8014. [COCI 2013/2014 #4] SUMO
[COCI 2013/2014 #4] SUMO
Problem Description
There are players participating in one-on-one matches, and the match order has already been fixed.
Now you need to divide these players into teams, so that players meet opponents from the same team as late as possible.
Output the match index of the first match in which a player meets a player from the same team, under the optimal division.
Input Format
The first line contains a positive integer , meaning there are players.
The second line contains a positive integer , meaning there are matches.
The next lines each contain two positive integers and , meaning the players in match are player and player .
Output Format
Output one line containing a positive integer, the match index of the first match in which a player meets a player from the same team under the optimal team division.
5
5
1 2
2 3
3 4
4 5
5 1
5
6
8
1 2
3 4
5 6
1 3
1 6
4 5
2 4
2 6
6
Hint
Sample Explanation #1
are in one team, and are in the other team.
It can be proven that this is the optimal division.
Constraints
For of the testdata, and .
Source
The score of this problem follows the original COCI settings, with a full score of .
Translated from COCI2013-2014 CONTEST #4 T3 SUMO。
Translated by ChatGPT 5