-
Notifications
You must be signed in to change notification settings - Fork 0
/
How Many Dependencies_10926.cpp
84 lines (64 loc) · 1.12 KB
/
How Many Dependencies_10926.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using namespace std;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<bitset>
#include<map>
#include<set>
#include<climits>
#include<algorithm>
#include<utility>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<sstream>
#define read(x) scanf("%d",&x)
#define write(x) printf("%d\n",x)
#define assign(x,n) x=(int*)calloc(n,4)
#define rep(i,n) for(i=1;i<=n;++i)
#define max(a,b) ((a)>(b))?(a):(b)
typedef long long int ull;
vector <int> v[102];
int *visited,mx,pos;
int dfs(int s)
{
int i,j=0,k;
for(i=0;i<v[s].size();i++)
if(!visited[v[s][i]])
{
visited[v[s][i]]=1;
j+=dfs(v[s][i])+1;
}
return j;
}
int main()
{
int n,i,j,k;
while(read(n)!=EOF && n)
{
for(i=1;i<=n;i++)
{
read(j);
while(j--)
{
read(k);
v[i].push_back(k);
}
}
mx=-1;pos=n;
for(i=1;i<=n;i++)
{
assign(visited,n+1);
j=dfs(i);
if(j>mx){mx=j;pos=i;}
//cout<<i<<" "<<j<<endl;
}
for(i=1;i<=n;i++)
v[i].clear();
write(pos);
}
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
}