1021 Deepest Root (25 分)   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 r…
PAT甲级1021. Deepest Root 题意: 连接和非循环的图可以被认为是一棵树.树的高度取决于所选的根.现在你应该找到导致最高树的根.这样的根称为最深根. 输入规格: 每个输入文件包含一个测试用例.对于每种情况, 第一行包含正整数N(<= 10000),它是节点的数量,因此节点从1到N编号.然后按N-1行,每个都通过给定两个相邻节点的数字来描述一个边. 输出规格: 对于每个测试用例,打印一行中最深的根.如果这样的根不是唯一的, 打印他们的数字增加的顺序.在给定的图形不是树的情况下,打…
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…
https://pintia.cn/problem-sets/994805342720868352/problems/994805482919673856 A graph which is connected and acyclic can be considered a tree. The hight of the tree depends on the selected root. Now you are supposed to find the root that results in a…
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…
题意: 输入一个正整数N(N<=10000),然后输入N-1条边,求使得这棵树深度最大的根节点,递增序输出.如果不是一棵树,输出这张图有几个部分. trick: 时间比较充裕数据可能也不是很极限,所以用了一个暴力的手段.直接枚举度数为1的点进行深度优先搜索,如果递归了一万次还没有return就当它有环.(这道题的数据不存在只有一个带有自环的部分,即如有自环图必定不止一个)正解应当是dfs一次以后找到一些可能是最深根的叶子结点们,然后对这些叶子节点们依次dfs,再找到对应的一些叶子节点们.成对的叶…
1021 Deepest Root (25)(25 分)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…
http://pat.zju.edu.cn/contests/pat-a-practise/1021 无环连通图也可以视为一棵树,选定图中任意一点作为根,如果这时候整个树的深度最大,则称其为 deepest root. 给定一个图,按升序输出所有 deepest root.如果给定的图有多个连通分量,则输出连通分量的数量. 1.使用并查集判断图是否为连通的. 2.任意选取一点,做 dfs 搜索,选取其中一个最远距离的点 A,再做一次 dfs,找到的所有距离最远的点以及点 A 都是 deepest…
1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tre…
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…