#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
#ifdef LOCAL
template<typename A, typename B>
auto&operator<<(auto&o,pair<A, B>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<&","[!i++]<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
using i64 = long long;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<i64, i64>;
using vi = vector<int>;
using vll = vector<i64>;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(14);
cerr << fixed << setprecision(6);
int num_days, sz_first;
cin >> num_days >> sz_first;
vector<vi> prev_req_meeting;
vector<vi> meeting_occupancy;
prev_req_meeting.push_back(vi(sz_first));
meeting_occupancy.push_back(vi(sz_first));
for (int d = 1; d < num_days; ++d) {
int sz_d;
cin >> sz_d;
prev_req_meeting.push_back(vi(sz_d));
meeting_occupancy.push_back(vi(sz_d));
for (int &x : prev_req_meeting.back()) {
cin >> x;
}
}
int answer = 0;
for (int d = num_days - 1; d >= 0; --d) {
for (int &x : meeting_occupancy[d]) {
x = max(x, 1);
}
const int needed_on_day_d = accumulate(ALL(meeting_occupancy[d]), 0);
answer = max(answer, needed_on_day_d);
for (int i = 0; i < SZ(meeting_occupancy[d]); ++i) {
const int prev_idx = prev_req_meeting[d][i];
if (prev_idx) {
meeting_occupancy[d - 1][prev_idx - 1] += meeting_occupancy[d][i];
}
}
}
cout << answer << "\n";
}
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 64 65 | #include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) using namespace std; #ifdef LOCAL template<typename A, typename B> auto&operator<<(auto&o,pair<A, B>p){return o<<"("<<p.first<<", "<<p.second<<")";} auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<&","[!i++]<<e;return o<<"}";} #define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X) #else #define debug(...){} #endif using i64 = long long; using ll = long long; using pii = pair<int, int>; using pll = pair<i64, i64>; using vi = vector<int>; using vll = vector<i64>; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(14); cerr << fixed << setprecision(6); int num_days, sz_first; cin >> num_days >> sz_first; vector<vi> prev_req_meeting; vector<vi> meeting_occupancy; prev_req_meeting.push_back(vi(sz_first)); meeting_occupancy.push_back(vi(sz_first)); for (int d = 1; d < num_days; ++d) { int sz_d; cin >> sz_d; prev_req_meeting.push_back(vi(sz_d)); meeting_occupancy.push_back(vi(sz_d)); for (int &x : prev_req_meeting.back()) { cin >> x; } } int answer = 0; for (int d = num_days - 1; d >= 0; --d) { for (int &x : meeting_occupancy[d]) { x = max(x, 1); } const int needed_on_day_d = accumulate(ALL(meeting_occupancy[d]), 0); answer = max(answer, needed_on_day_d); for (int i = 0; i < SZ(meeting_occupancy[d]); ++i) { const int prev_idx = prev_req_meeting[d][i]; if (prev_idx) { meeting_occupancy[d - 1][prev_idx - 1] += meeting_occupancy[d][i]; } } } cout << answer << "\n"; } |
English