传送门 The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any…
题目链接:https://cn.vjudge.net/contest/277955#problem/C 题目大意:输入n,代表有n个城市,然后再输入n-1条有向边,然后让你找出一个改变边数的最小值,使得某个城市能够到达剩余的所有城市,然后问这样的城市有多少个,并且输出这些城市的编号.  具体思路:我们首先按照题目给的条件建好边,然后树就建好了,对于当前的某个节点,如果这个点要是能够到达剩余的所有城市,从这个节点往上的话,这个节点连接的父亲节点的这条边应该是是从子节点到父节点的.从这个节点往下的话…
D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Over…
题目传送门 /* 题意:求一个点为根节点,使得到其他所有点的距离最短,是有向边,反向的距离+1 树形DP:首先假设1为根节点,自下而上计算dp[1](根节点到其他点的距离),然后再从1开始,自上而下计算dp[v], 此时可以从上个节点的信息递推出来 */ #include <cstdio> #include <cstring> #include <cmath> #include <vector> using namespace std; ; const in…
Choosing Capital for Treeland Description The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the direction of the roads in…
Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall…
D. Choosing Capital for Treeland 链接:http://codeforces.com/problemset/problem/219/D   The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if…
D. Choosing Capital for Treeland 题意 给出一颗有方向的n个节点的树,现在要选择一个点作为首都. 问最少需要翻转多少条边,使得首都可以到所有其他的城市去,以及相应的首都可以是哪些点. 思路 先忽略掉树中的方向,dp[i]表示i节点到它的子树所有点最少需要翻转的边. 进行第一遍dfs 如果u-v的方向是u-->v,那么dp[u]=dp[u]+dp[v];,否则dp[u]=dp[u]+dp[v]+1;,表示u-v这条边要翻转. 这时根节点的dp值就是根节点作为首都需要…
D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Over…
D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Over…