#include <bits/stdc++.h>
using namespace std;
const int mxn = 500005;
vector<pair<int,long long>> spo[mxn];
long long mx;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int k, n; cin >> k >> n;
spo[0].assign(n, {0,0});
spo[1].assign(n, {0,0});
for (int i = 2; i <= k; i++){
cin >> n;
spo[i].assign(n, {0, 0});
for (int j = 0; j < n; j++)
cin >> spo[i][j].first;
}
for (int i = k; i >= 1; i--){
long long res = 0;
for (int j = 0; j < spo[i].size(); j++){
if (!spo[i][j].second)
spo[i][j].second = 1;
res += spo[i][j].second;
if (spo[i][j].first)
spo[i-1][spo[i][j].first-1].second += spo[i][j].second;
}
mx = max(res, mx);
}
cout << mx << '\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 | #include <bits/stdc++.h> using namespace std; const int mxn = 500005; vector<pair<int,long long>> spo[mxn]; long long mx; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int k, n; cin >> k >> n; spo[0].assign(n, {0,0}); spo[1].assign(n, {0,0}); for (int i = 2; i <= k; i++){ cin >> n; spo[i].assign(n, {0, 0}); for (int j = 0; j < n; j++) cin >> spo[i][j].first; } for (int i = k; i >= 1; i--){ long long res = 0; for (int j = 0; j < spo[i].size(); j++){ if (!spo[i][j].second) spo[i][j].second = 1; res += spo[i][j].second; if (spo[i][j].first) spo[i-1][spo[i][j].first-1].second += spo[i][j].second; } mx = max(res, mx); } cout << mx << '\n'; return 0; } |
English