#include <bits/stdc++.h>
using namespace std;
int n,k,a;
int sum;
vector<vector<int> > v;
int main()
{
std::ios_base::sync_with_stdio(0);
cin>>k>>n;
v.resize(k, vector<int>(0,0));
v[0].resize(n,0);
for(int i=1;i<k;i++){
int j;
cin>>j;
while(j--){
cin>>a;
v[i].push_back(a);
}
}
vector<int> now, nxt;
now.resize(v.back().size(), 0);
for(int i=v.size()-1; i>0; i--){
nxt.resize(0);
nxt.resize(v[i-1].size());
for(int j=0;j<now.size();j++)
{
if(now[j] == 0){
now[j]=1;
if(sum)sum--;
}
}
for(int j=0; j<v[i].size(); j++){
if(v[i][j] != 0)nxt[v[i][j]-1] += now[j];
else sum += now[j];
}
now = nxt;
}
for(int j=0;j<now.size();j++)
{
if(now[j] == 0){
now[j]=1;
if(sum)sum--;
}
}
for(int ile : now) sum += ile;
cout << sum;
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 | #include <bits/stdc++.h> using namespace std; int n,k,a; int sum; vector<vector<int> > v; int main() { std::ios_base::sync_with_stdio(0); cin>>k>>n; v.resize(k, vector<int>(0,0)); v[0].resize(n,0); for(int i=1;i<k;i++){ int j; cin>>j; while(j--){ cin>>a; v[i].push_back(a); } } vector<int> now, nxt; now.resize(v.back().size(), 0); for(int i=v.size()-1; i>0; i--){ nxt.resize(0); nxt.resize(v[i-1].size()); for(int j=0;j<now.size();j++) { if(now[j] == 0){ now[j]=1; if(sum)sum--; } } for(int j=0; j<v[i].size(); j++){ if(v[i][j] != 0)nxt[v[i][j]-1] += now[j]; else sum += now[j]; } now = nxt; } for(int j=0;j<now.size();j++) { if(now[j] == 0){ now[j]=1; if(sum)sum--; } } for(int ile : now) sum += ile; cout << sum; return 0; } |
English