-
Notifications
You must be signed in to change notification settings - Fork 185
/
10926.cc
43 lines (43 loc) · 839 Bytes
/
10926.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// https://uva.onlinejudge.org/external/109/10926.pdf
#include<bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using si=unordered_set<int>;
using vsi=vector<si>;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
for(;;){
int n,m,u,v;
cin>>n;
if(!n)break;
vvi g(n);
for(int i=0;i<n;i++){
cin>>m;
g[i]=vi(m);
for(int j=0;j<m;j++){
cin>>u;
g[i][j]=u-1;
}
}
vsi a(n);
function<void(int)>dfs=[&](int u){
a[u].insert(u);
for(int v:g[u]){
if(a[v].empty())dfs(v);
for(int x:a[v])a[u].insert(x);
}
};
for(int i=0;i<n;i++)
if(a[i].empty())
dfs(i);
int M=0,k;
for(int i=0;i<n;i++)
if(a[i].size()>M){
M=a[i].size();
k=i+1;
}
cout<<k<<"\n";
}
}