#include <iostream>
#include <vector>
#include <numeric>
int main(int argc, char* argv[]) {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int K, N;
std::cin >> K >> N;
std::vector<std::vector<int>> parent(K), required_staff(K);
parent[0].resize(N, -1);
required_staff[0].resize(N);
for (int day = 1; day < K; ++day) {
int N;
std::cin >> N;
parent[day].resize(N);
required_staff[day].resize(N);
for (int& p : parent[day]) {
std::cin >> p;
p--;
}
}
for (int day = K-1; day >= 0; --day) {
for (int talk = 0; talk < (int)parent[day].size(); talk++) {
int& req_staff = required_staff[day][talk];
if (req_staff == 0) {
req_staff = 1;
}
int p = parent[day][talk];
if (p != -1) {
required_staff[day - 1][p] += req_staff;
}
}
}
int result = 0;
for (const auto& day : required_staff) {
result = std::max(result, std::accumulate(day.begin(), day.end(), 0));
}
std::cout << result << '\n';
return 0;
}
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 | #include <iostream> #include <vector> #include <numeric> int main(int argc, char* argv[]) { std::ios_base::sync_with_stdio(0); std::cin.tie(0); int K, N; std::cin >> K >> N; std::vector<std::vector<int>> parent(K), required_staff(K); parent[0].resize(N, -1); required_staff[0].resize(N); for (int day = 1; day < K; ++day) { int N; std::cin >> N; parent[day].resize(N); required_staff[day].resize(N); for (int& p : parent[day]) { std::cin >> p; p--; } } for (int day = K-1; day >= 0; --day) { for (int talk = 0; talk < (int)parent[day].size(); talk++) { int& req_staff = required_staff[day][talk]; if (req_staff == 0) { req_staff = 1; } int p = parent[day][talk]; if (p != -1) { required_staff[day - 1][p] += req_staff; } } } int result = 0; for (const auto& day : required_staff) { result = std::max(result, std::accumulate(day.begin(), day.end(), 0)); } std::cout << result << '\n'; return 0; } |
English