CF238C.World Eater Brothers
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You must have heard of the two brothers dreaming of ruling the world. With all their previous plans failed, this time they decided to cooperate with each other in order to rule the world.
As you know there are n countries in the world. These countries are connected by n - 1 directed roads. If you don't consider direction of the roads there is a unique path between every pair of countries in the world, passing through each road at most once.
Each of the brothers wants to establish his reign in some country, then it's possible for him to control the countries that can be reached from his country using directed roads.
The brothers can rule the world if there exists at most two countries for brothers to choose (and establish their reign in these countries) so that any other country is under control of at least one of them. In order to make this possible they want to change the direction of minimum number of roads. Your task is to calculate this minimum number of roads.
你一定听说过那对梦想统治世界的兄弟。在之前的所有计划都失败后,这次他们决定合作以统治世界。
众所周知,世界上共有 n 个国家。这些国家由 n−1 条有向道路连接。若忽略道路的方向,则世界上任意两个国家之间均存在唯一一条路径(每条道路至多经过一次)。
每位兄弟希望在某个国家建立自己的统治,之后他便能控制所有从该国出发、沿有向道路可达的国家。
当且仅当存在至多两个国家供兄弟二人选择(并在这些国家建立统治),使得其余任意国家至少处于其中一位兄弟的控制之下时,兄弟二人便可统治世界。为使这一目标成为可能,他们希望反转最少数量的道路方向。你的任务是计算这个最少需要反转的道路数目。
输入格式
The first line of input contains an integer n (1 ≤ n ≤ 3000). Each of the next n - 1 lines contains two space-separated integers a__i and b__i (1 ≤ a__i, b__i ≤ n; a__i ≠ b__i) saying there is a road from country a__i to country b__i.
Consider that countries are numbered from 1 to n. It's guaranteed that if you don't consider direction of the roads there is a unique path between every pair of countries in the world, passing through each road at most once.
输入的第一行包含一个整数 n(1≤n≤3000)。接下来的 n−1 行中,每行包含两个以空格分隔的整数 ai 和 bi(1≤ai,bi≤n;ai=bi),表示存在一条从国家 ai 到国家 bi 的道路。
假设国家编号为 1 到 n。保证:若忽略道路的方向,则世界上任意两个国家之间均存在唯一的一条路径(每条道路至多经过一次)。
输出格式
In the only line of output print the minimum number of roads that their direction should be changed so that the brothers will be able to rule the world.
在输出的唯一一行中,打印 brothers 要统治世界所需改变方向的最少道路数量。
输入输出样例
输入#1
4 2 1 3 1 4 1
输出#1
1
输入#2
5 2 1 2 3 4 3 4 5
输出#2
0
输入解题思路,AI测评打分。不知道怎么写?