A818 | Cow at Large--Gold
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Cornered at last, Bessie has gone to ground in a remote farm. The farm
consists of $N$ barns ($2 \leq N \leq 10^5$) and $N-1$ bidirectional tunnels
between barns, so that there is a unique path between every pair of barns.
Every barn which has only one tunnel is an exit. When morning comes, Bessie
will surface at some barn and attempt to reach an exit.
But the moment Bessie surfaces, the law will be able to pinpoint her location.
Some farmers will then start at various exit barns, and attempt to catch
Bessie. The farmers move at the same speed as Bessie (so in each time step,
each farmer can move from one barn to an adjacent barn). The farmers know
where Bessie is at all times, and Bessie knows where the farmers are at all
times. The farmers catch Bessie if at any instant a farmer is in the same barn
as Bessie, or crossing the same tunnel as Bessie. Conversely, Bessie escapes
if she reaches an exit barn before any farms catch her.
Bessie is unsure about her chances of success, which depends on the number of
farmers that the law is able to deploy. Given that Bessie surfaces at barn
$K$, help Bessie determine the minimum number of farmers who would be needed
to catch Bessie, assuming that the farmers distribute themselves optimally
among the exit barns.
consists of $N$ barns ($2 \leq N \leq 10^5$) and $N-1$ bidirectional tunnels
between barns, so that there is a unique path between every pair of barns.
Every barn which has only one tunnel is an exit. When morning comes, Bessie
will surface at some barn and attempt to reach an exit.
But the moment Bessie surfaces, the law will be able to pinpoint her location.
Some farmers will then start at various exit barns, and attempt to catch
Bessie. The farmers move at the same speed as Bessie (so in each time step,
each farmer can move from one barn to an adjacent barn). The farmers know
where Bessie is at all times, and Bessie knows where the farmers are at all
times. The farmers catch Bessie if at any instant a farmer is in the same barn
as Bessie, or crossing the same tunnel as Bessie. Conversely, Bessie escapes
if she reaches an exit barn before any farms catch her.
Bessie is unsure about her chances of success, which depends on the number of
farmers that the law is able to deploy. Given that Bessie surfaces at barn
$K$, help Bessie determine the minimum number of farmers who would be needed
to catch Bessie, assuming that the farmers distribute themselves optimally
among the exit barns.
输入格式
The first line of the input contains $N$ and $K$. Each of the following $N-1$
lines specify two integers, each in the range $1 \ldots N$, describing a
tunnel between two barns.
lines specify two integers, each in the range $1 \ldots N$, describing a
tunnel between two barns.
输出格式
Please output the minimum number of farmers needed to ensure catching Bessie.
输入输出样例
输入 #1
7 1 1 2 1 3 3 4 3 5 4 6 5 7
输出 #1
3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted