#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int k,n; cin>>k>>n;
vector<vector<pair<int, bool>>> tree(1, vector<pair<int, bool>>(n, make_pair(0, true)));
for(int i=1;i<k;i++){
cin>>n;
tree.push_back(vector<pair<int, bool>>(n, make_pair(i, true)));
for(int j=0;j<n;j++){
int x; cin>>x; x--;
if(x+1){
tree[i-1][x].second=false;
tree[i][j].first=tree[i-1][x].first;
}
}
}
vector<int> wyd(k+1, 0);
for(int i=0;i<k;i++){
for(auto [a,g]: tree[i]){
if(g){
wyd[a]+=1;
wyd[i+1]-=1;
}
}
}
int s=0;
int mx=0;
for(int i=0;i<k;i++){
s+=wyd[i];
mx=max(mx, s);
}
cout<<mx;
}
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 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int k,n; cin>>k>>n; vector<vector<pair<int, bool>>> tree(1, vector<pair<int, bool>>(n, make_pair(0, true))); for(int i=1;i<k;i++){ cin>>n; tree.push_back(vector<pair<int, bool>>(n, make_pair(i, true))); for(int j=0;j<n;j++){ int x; cin>>x; x--; if(x+1){ tree[i-1][x].second=false; tree[i][j].first=tree[i-1][x].first; } } } vector<int> wyd(k+1, 0); for(int i=0;i<k;i++){ for(auto [a,g]: tree[i]){ if(g){ wyd[a]+=1; wyd[i+1]-=1; } } } int s=0; int mx=0; for(int i=0;i<k;i++){ s+=wyd[i]; mx=max(mx, s); } cout<<mx; } |
English