-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path924.cpp
More file actions
78 lines (75 loc) · 1.79 KB
/
924.cpp
File metadata and controls
78 lines (75 loc) · 1.79 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* ____
* ____ ___ ____ ________ __/ __/
* / __ `__ \/ __ `/ ___/ / / / /_
* / / / / / / /_/ / / / /_/ / __/
* /_/ /_/ /_/\__,_/_/ \__,_/_/
*
* @link : https://the-redback.com
*/
#include <bits/stdc++.h>
using namespace std;
#define inf HUGE_VAL
#define mem(a, b) memset(a, b, sizeof(a))
#define NN 2500
int dist[NN + 7];
vector<int> edge[NN + 7];
queue<int> q;
int day[NN + 7];
int bfs(int src) {
int i, j, k;
mem(dist, -1);
mem(day, 0);
q = queue<int>();
q.push(src);
dist[src] = 0;
int ret = -1;
int cnt = 0;
while (!q.empty()) {
k = q.front();
q.pop();
cnt = 0;
for (i = 0; i < edge[k].size(); i++) {
if (dist[edge[k][i]] == -1) {
q.push(edge[k][i]);
dist[edge[k][i]] = dist[k] + 1;
day[dist[k] + 1]++;
ret = 1;
}
}
}
return ret;
}
int main() {
int tc, t = 1;
int n, i, j, k, l, p, r, m;
int sum = 0;
while (~scanf("%d", &tc)) {
for (i = 0; i < tc; i++) {
scanf("%d", &k);
while (k--) {
scanf("%d", &l);
edge[i].push_back(l);
}
}
scanf("%d", &p);
while (p--) {
scanf("%d", &k);
n = bfs(k);
if (n == -1)
puts("0");
else {
int bday = 0;
k = -1;
for (i = 1; i <= tc; i++)
if (day[i] > k) {
bday = i;
k = day[i];
}
printf("%d %d\n", k, bday);
}
}
for (i = 0; i <= tc; i++) edge[i].clear();
}
return 0;
}