标签:lan mes ios string scan memset ++ span using
建树、找根、找最深的叶子节点
#include<iostream> #include<cstdio> #include<vector> #include<algorithm> #include<cstring> #include<string> #include<map> #include<queue> #include<iomanip> using namespace std; #define STDIN freopen("in.in", "r", stdin);freopen("out.out", "w", stdout); const int N = 100000 + 10; int h[N], e[N*100], ne[N*100], idx; int du[N]; void add(int a, int b) { e[idx] = b; ne[idx] = h[a]; h[a] = idx++; } int ans = 1, de = 0; void dfs(int u, int d) { if (d > de) { ans = u, de = d; } for (int i = h[u]; ~i; i = ne[i]) { int j = e[i]; dfs(j, d + 1); } } int main() { STDIN int n; cin >> n; memset(h, -1, sizeof h); add(0,1); for (int i = 1; i <= n; i++) { int k; scanf("%d", &k); int x; for (int j = 1; j<= k; j++) { scanf("%d", &x); add(i, x); du[x]++; } } int ru; for (int i = 1; i <= n; i++) { if (!du[i]) { ru = i; break; } } dfs(ru, 0); cout << ans << endl; }
标签:lan mes ios string scan memset ++ span using
原文地址:https://www.cnblogs.com/hulian425/p/14031913.html