第一次出现超时 ac不了的题 思路一:对于每个节点用一次dfs dfs中 记录到当前的最长路径,若大于最长,则清除set,并加入当前节点 思路二:先查找只有一个相邻节点的节点进行dfs,由于可能存在闭环,对为访问的节点dfs 思路三:(TQL),大神思路,先以1节点为根用一次dfs(1),求出以1为根的最深点集合,并且完成深度搜索一次,可以知道是否还有不可达点, 如果还有没访问,继续遍历,可以的到连通分量数. 如果大于1,直接打印错误信息 否则,对最深点集合的其中一个进行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…
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…
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…
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…
PAT甲级1021. Deepest Root 题意: 连接和非循环的图可以被认为是一棵树.树的高度取决于所选的根.现在你应该找到导致最高树的根.这样的根称为最深根. 输入规格: 每个输入文件包含一个测试用例.对于每种情况, 第一行包含正整数N(<= 10000),它是节点的数量,因此节点从1到N编号.然后按N-1行,每个都通过给定两个相邻节点的数字来描述一个边. 输出规格: 对于每个测试用例,打印一行中最深的根.如果这样的根不是唯一的, 打印他们的数字增加的顺序.在给定的图形不是树的情况下,打…
http://pat.zju.edu.cn/contests/pat-a-practise/1021 无环连通图也可以视为一棵树,选定图中任意一点作为根,如果这时候整个树的深度最大,则称其为 deepest root. 给定一个图,按升序输出所有 deepest root.如果给定的图有多个连通分量,则输出连通分量的数量. 1.使用并查集判断图是否为连通的. 2.任意选取一点,做 dfs 搜索,选取其中一个最远距离的点 A,再做一次 dfs,找到的所有距离最远的点以及点 A 都是 deepest…
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…
题目如下: 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 Specificat…
dfs求最大层数并查集求连通个数 #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <string> #include <vector> using namespace std; /* dfs求最大层数 并查集求连通个数 */ +; int n; ; //最大层数 vector<int>deepro…