#include <iostream>
#include <vector>
using namespace std;
void vecvecp(vector<std::vector<int>> spot) {
for (int i=0; i<spot.size(); i++) {
cout << i << ": ";
for (int j=0; j<spot[i].size(); j++)
cout << spot[i][j] << " ";
cout << endl;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int n1,k,p,l1;
cin >> k >> n1;
vector<std::vector<int>> spot(k);
vector<std::vector<int>> snum(k);
for (int i=0; i<=n1; i++) {
spot[0].push_back(0);
snum[0].push_back(0);
}
for (int i=1; i<k; i++) {
cin >> p;
spot[i].push_back(p);
snum[i].push_back(0);
for (int j=0; j<p; j++) {
cin >> l1;
spot[i].push_back(l1);
snum[i].push_back(0);
}
}
int mos = 0;
int dmax, sp, sn;
for (int i=k-1; i>0; i--) {
dmax = 0;
for (int j=1; j<spot[i].size(); j++) {
sp = spot[i][j];
sn = snum[i][j];
dmax+= max(sn, 1);
snum[i-1][sp]+= max(sn, 1);
}
mos=max(dmax, mos);
}
dmax = 0;
for (int j=1; j<spot[0].size(); j++) {
dmax+= max(snum[0][j], 1);
mos=max(dmax, mos);
}
cout << mos << endl;
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <iostream> #include <vector> using namespace std; void vecvecp(vector<std::vector<int>> spot) { for (int i=0; i<spot.size(); i++) { cout << i << ": "; for (int j=0; j<spot[i].size(); j++) cout << spot[i][j] << " "; cout << endl; } } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n1,k,p,l1; cin >> k >> n1; vector<std::vector<int>> spot(k); vector<std::vector<int>> snum(k); for (int i=0; i<=n1; i++) { spot[0].push_back(0); snum[0].push_back(0); } for (int i=1; i<k; i++) { cin >> p; spot[i].push_back(p); snum[i].push_back(0); for (int j=0; j<p; j++) { cin >> l1; spot[i].push_back(l1); snum[i].push_back(0); } } int mos = 0; int dmax, sp, sn; for (int i=k-1; i>0; i--) { dmax = 0; for (int j=1; j<spot[i].size(); j++) { sp = spot[i][j]; sn = snum[i][j]; dmax+= max(sn, 1); snum[i-1][sp]+= max(sn, 1); } mos=max(dmax, mos); } dmax = 0; for (int j=1; j<spot[0].size(); j++) { dmax+= max(snum[0][j], 1); mos=max(dmax, mos); } cout << mos << endl; return(0); } |
English