A1333 | [COCI-2015_2016-olympiad]#4 Torrent
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko works at a data centre and today’s task is to copy a file sized 1 GiB to n computers. The computers are denoted with integers from 1 to n and are connected so that they form a so-called tree. More precisely, n − 1 pairs of computers are directly connected via network cable in a way that there is a unique path between each pair of computers.
Initially, Mirko manually placed the file on two different computers – computer a and computer b and is now writing commands that will copy the file to all other computers. The file can be copied from computer x to computer y only if the two computers are directly connected, and the copying process takes exactly one minute. At any moment, each individual computer can take part in at most one copying process, but it is allowed to have the file being copied between arbitrarily many different pairs of computers at the same time. Therefore, when the copying process ends from computer x to computer y, it is possible in the next minute to copy the file from computer x to computer w and from computer y to computer z.
Determine the minimal amount of time it takes for the file to be copied to all computers.
Initially, Mirko manually placed the file on two different computers – computer a and computer b and is now writing commands that will copy the file to all other computers. The file can be copied from computer x to computer y only if the two computers are directly connected, and the copying process takes exactly one minute. At any moment, each individual computer can take part in at most one copying process, but it is allowed to have the file being copied between arbitrarily many different pairs of computers at the same time. Therefore, when the copying process ends from computer x to computer y, it is possible in the next minute to copy the file from computer x to computer w and from computer y to computer z.
Determine the minimal amount of time it takes for the file to be copied to all computers.
输入格式
The first line of input contains the integer n and two different integers a and b (1 ≤ a, b ≤ n) – the number of computers and the labels of the computers already containing the file. Each of the following n − 1 lines contains two different integers x and y (1 ≤ x, y ≤ n) – the labels of the computers directly connected via network cable. The computer network forms a tree, as described in the task.
输出格式
You must output the required minimal amount of time in minutes.
输入输出样例
输入 #1
6 2 1 1 2 2 3 2 4 1 5 5 6
输出 #1
2
输入 #2
10 1 2 1 2 2 5 1 3 1 4 4 6 6 7 3 8 3 9 3 10
输出 #2
4
输入 #3
17 1 2 1 3 1 4 4 6 6 7 3 8 3 9 3 10 1 13 13 5 13 11 13 12 13 14 14 15 15 16 15 17 14 2
输出 #3
5
Subtask Score Limitations
1 31 2 ≤ n ≤ 1 000
2 69 1 000 ≤ n ≤ 300 000
1 31 2 ≤ n ≤ 1 000
2 69 1 000 ≤ n ≤ 300 000
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted