#include <bits/stdc++.h>
#define ll long long
#define pi std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi std::vector<int>
#define vll std::vector<ll>
#define vpi std::vector<pi>
#define vpll std::vector<pll>
#define si std::set<int>
void solve() {
ll k, n, max = 0;
std::cin >> k >> n;
std::vector<vll> v(k), count(k);
v[0].resize(n);
count[0].resize(n);
for(int i = 1; i < k; i++) {
std::cin >> n;
v[i].resize(n);
count[i].resize(n);
for(auto& el : v[i])
std::cin >> el;
}
for(int i = k - 1; i >= 0; i--) {
ll sum = 0;
for(int j = 0; j < v[i].size(); j++) {
if(!count[i][j])
count[i][j] = 1;
sum += count[i][j];
if(v[i][j] > 0)
count[i-1][v[i][j]-1] += count[i][j];
}
max = std::max(max, sum);
}
std::cout << max << '\n';
}
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int t = 1;
//std::cin >> t;
while(t--) {
solve();
}
}
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 | #include <bits/stdc++.h> #define ll long long #define pi std::pair<int, int> #define pll std::pair<ll, ll> #define vi std::vector<int> #define vll std::vector<ll> #define vpi std::vector<pi> #define vpll std::vector<pll> #define si std::set<int> void solve() { ll k, n, max = 0; std::cin >> k >> n; std::vector<vll> v(k), count(k); v[0].resize(n); count[0].resize(n); for(int i = 1; i < k; i++) { std::cin >> n; v[i].resize(n); count[i].resize(n); for(auto& el : v[i]) std::cin >> el; } for(int i = k - 1; i >= 0; i--) { ll sum = 0; for(int j = 0; j < v[i].size(); j++) { if(!count[i][j]) count[i][j] = 1; sum += count[i][j]; if(v[i][j] > 0) count[i-1][v[i][j]-1] += count[i][j]; } max = std::max(max, sum); } std::cout << max << '\n'; } int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); int t = 1; //std::cin >> t; while(t--) { solve(); } } |
English