-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path924.cpp
More file actions
executable file
·63 lines (61 loc) · 1.21 KB
/
924.cpp
File metadata and controls
executable file
·63 lines (61 loc) · 1.21 KB
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
#include <bits/stdc++.h>
using namespace std;
int const N=2509;
int main()
{
int n;
cin>>n;
vector<int> adj[n+1];
for(int i=0; i<n; i++)
{
int k;
cin>>k;
int a;
while(k--)
{
cin>>a;
adj[i].push_back(a);
//adj[a].push_back(i);
}
}
vector<bool> visited(n+1,false);
vector<int> d(n+1,0);
int T,p;
cin>>T;
while(T--)
{
cin>>p;
visited.assign(n+1,false);
d.assign(n+1,0);
queue<int> q;
q.push(p);
visited[p]=true;
int f[2509]={0};
while(!q.empty())
{
int v=q.front();
q.pop();
for(int u:adj[v])
{
if(!visited[u])
{
visited[u]=true;
d[u]=d[v]+1;
f[d[u]]++;
q.push(u);
}
}
}
int max=-1,id;
for(int i=0; i<=2505; i++)
{
if(f[i]>max)
{
max=f[i];
id=i;
}
}
if(max==0)cout<<0<<endl;
else cout<<max<<" "<<id<<endl;
}
}