L2-3 娣卞叆铏庣┐ (25鍒?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了L2-3 娣卞叆铏庣┐ (25鍒?相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/lan' title='lan'>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; }
以上是关于L2-3 娣卞叆铏庣┐ (25鍒?的主要内容,如果未能解决你的问题,请参考以下文章
viewport銆佸竷灞€瑙嗗彛銆佽瑙夎鍙c€佺悊鎯宠鍙?娣卞叆鐞嗚В