国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1021. Deepest Root (25)

2019-11-08 02:01:01
字體:
來源:轉載
供稿:網友
#include <cstdio>#include <algorithm>#include <vector>#include <cstring>using namespace std;const int maxn = 10010;int deepest = 0;vector<int> city[maxn];int deep_r[maxn], p = 0;bool visit[maxn] = {false};bool visit1[maxn] = {false};void DFS(int root) {	visit[root] = true;	for (int i = 0; i < city[root].size(); i++) {		if (visit[city[root][i]]) continue;		DFS(city[root][i]); 	}}void DFS(int root, int level) {	visit[root] = true;	bool flag = false;	for (int i = 0; i < city[root].size(); i++) {		if (visit[city[root][i]]) continue;		DFS(city[root][i], level + 1);		flag = true;	}	if (flag == false) {		if (level > deepest) {			deepest = level;			p = 0;			memset(visit1, false, sizeof(visit1));		}		if (level == deepest && visit1[root] == false) {			deep_r[p++] = root;			visit1[root] = true;		}	}}int main() {	int n;	scanf("%d", &n);	int c1, c2;	for (int i = 1; i < n; i++) {		scanf("%d%d", &c1, &c2);		city[c1].push_back(c2);		city[c2].push_back(c1);	}		int block = 0;	for (int i = 1; i <= n; i++) {		if (visit[i] == false) {			block++;			DFS(i);		}	}		if (block > 1) {		PRintf("Error: %d components/n", block);	} else {		for (int i = 1; i <= n; i++) {			memset(visit, false, sizeof(visit));			DFS(i, 0);		}		sort(deep_r, deep_r + p);		for (int i = 0; i != p; i++) {			printf("%d/n", deep_r[i]);		}	}	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳东县| 台州市| 依兰县| 金塔县| 绥芬河市| 云浮市| 栾城县| 定兴县| 图们市| 迁西县| 两当县| 方正县| 宜兴市| 平定县| 宝清县| 清流县| 古交市| 清远市| 东莞市| 富川| 通河县| 巴彦淖尔市| 沈丘县| 钟祥市| 班戈县| 阜平县| 鲜城| 东源县| 宁夏| 平乐县| 福清市| 兴安县| 福鼎市| 泉州市| 伊川县| 长岛县| 江安县| 江门市| 成武县| 沧州市| 万安县|