PAT1021】的更多相关文章

1021. Deepest Root (25) 时间限制 1500 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root t…
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root. Input Specification: E…
之前不知道怎么判断是不是树,参考了 http://blog.csdn.net/eli850934234/article/details/8926263 但是最后有一个测试点有超时,在bfs里我用了数组拷贝,所以简化成直接访问超时就没有了. #include <iostream> #include <vector> #include <queue> #include <cstring> using namespace std; int bing[10005];…
给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0),请编写程序统计每种不同的个位数字出现的次数.例如:给定N = 100311,则有2个0,3个1,和1个3. 输入格式: 每个输入包含1个测试用例,即一个不超过1000位的正整数N. 输出格式: 对N中每一种不同的个位数字,以D:M的格式在一行中输出该位数字D及其在N中出现的次数M.要求按D的升序输出. 输入样例: 100311 输出样例:…
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root. Input Specification: E…
PAT甲级1021. Deepest Root 题意: 连接和非循环的图可以被认为是一棵树.树的高度取决于所选的根.现在你应该找到导致最高树的根.这样的根称为最深根. 输入规格: 每个输入文件包含一个测试用例.对于每种情况, 第一行包含正整数N(<= 10000),它是节点的数量,因此节点从1到N编号.然后按N-1行,每个都通过给定两个相邻节点的数字来描述一个边. 输出规格: 对于每个测试用例,打印一行中最深的根.如果这样的根不是唯一的, 打印他们的数字增加的顺序.在给定的图形不是树的情况下,打…