A1303 | [COCI-2013_2014-contest4]#4 SUMO
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
In a Japanese monastery, otherwise known for serious fasting and ascetic life, the Head of the sumo wrestling section has decided to organise training-competitions for his N fighters. He determined the exact sequence of M fights and its participants (two fighters face each other per fight).
Just moments before the competition, the Head realised he could easily stir things up a bit! He could divide his fighters into two teams so that only fighters of different teams face each other in each fight.
Since the fighting schedule has already been made and it doesn't meet this condition, and we mustn't change it for whatever zen reason there is, the Head is left with only one option. That is to divide the fighters into two teams so that the fighters from the same team face each other in a fight as late as possible.
Help the Head! For a given fighting schedule, determine the ordinal number of the first fight where two fighters from the same team have to face each other, under the condition that we divide them in the best possible way, so that the required fight takes place as late as possible. In all test data, such fight will definitely occur.
Just moments before the competition, the Head realised he could easily stir things up a bit! He could divide his fighters into two teams so that only fighters of different teams face each other in each fight.
Since the fighting schedule has already been made and it doesn't meet this condition, and we mustn't change it for whatever zen reason there is, the Head is left with only one option. That is to divide the fighters into two teams so that the fighters from the same team face each other in a fight as late as possible.
Help the Head! For a given fighting schedule, determine the ordinal number of the first fight where two fighters from the same team have to face each other, under the condition that we divide them in the best possible way, so that the required fight takes place as late as possible. In all test data, such fight will definitely occur.
输入格式
The first line of input contains the integer N (1 ≤ N ≤ 100 000), the number of fighters. The fighters are marked with numbers from 1 to N.
The second line of input contains the integer M (1 ≤ M ≤ 300 000), the number of fights.
Each of the following M lines contains fights in the order which they must take place. Each line contains two different integers from the interval [1, N]: the labels of fighters who are going to face each other.
The second line of input contains the integer M (1 ≤ M ≤ 300 000), the number of fights.
Each of the following M lines contains fights in the order which they must take place. Each line contains two different integers from the interval [1, N]: the labels of fighters who are going to face each other.
输出格式
The first and only line of output must contain the ordinal number (from 1 to M) of the required fight.
输入输出样例
输入 #1
5 5 1 2 2 3 3 4 4 5 5 1
输出 #1
5
输入 #2
6 8 1 2 3 4 5 6 1 3 1 6 4 5 2 4 2 6
输出 #2
6
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted