-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path924.cpp
65 lines (56 loc) · 1.75 KB
/
924.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
#include <algorithm>
#include <array>
#include <iostream>
#include <queue>
#include <vector>
int main(void)
{
int num_employee, num_cases;
std::array<std::vector<int>, 2500> friends;
std::queue<int> wait;
std::array<bool, 2500> seen;
std::array<int, 2500> expand, receive;
int size, target, left, max_day;
std::cin >> num_employee;
for (int i = 0; i < num_employee; ++i) {
std::cin >> size;
friends[i].resize(size);
for (int j = 0; j < size; ++j)
std::cin >> friends[i][j];
}
std::cin >> num_cases;
while (num_cases--) {
seen.fill(false);
expand.fill(0);
receive.fill(0);
std::cin >> target;
wait.push(target);
seen[target] = true;
max_day = 0;
left = num_employee;
while (!wait.empty()) {
auto curr = wait.front();
for (const auto &f : friends[curr]) {
if (!seen[f]) {
wait.push(f);
seen[f] = true;
receive[f] = receive[curr] + 1;
++expand[receive[curr]];
}
}
if (expand[receive[curr]] > expand[max_day])
max_day = receive[curr];
wait.pop();
if (left + expand[receive[curr]] < expand[max_day] &&
receive[curr] != max_day) {
while (!wait.empty())
wait.pop();
}
}
if (!expand[0])
std::cout << 0 << std::endl;
else
std::cout << expand[max_day] << " " << ++max_day << std::endl;
}
return 0;
}