#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll meeting_to_day[600600];
vector<ll> nbhs[600600];
vector<pair<ll, char>> q;
void bfs(ll v, ll r) {
vector<ll> bq;
bq.push_back(v);
while(bq.size()) {
ll u = bq.back();
bq.pop_back();
for(auto w: nbhs[u]) {
bq.push_back(w);
}
if(nbhs[u].size() == 0) {
q.push_back({meeting_to_day[r], 'A'});
q.push_back({meeting_to_day[u], 'D'});
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll k, n;
cin >> k >> n;
vector<ll> roots;
ll id = 0LL;
for(id = 1LL; id <= n; id++) {
meeting_to_day[id] = 1LL;
roots.push_back(id);
}
ll last_id = 1;
for(ll i = 2LL; i <= k; i++) {
cin >> n;
ll new_last_id = id;
for(int j = 0LL; j < n; j++, id++) {
ll a;
cin >> a;
meeting_to_day[id] = i;
if(a == 0LL) {
roots.push_back(id);
} else {
nbhs[last_id + a - 1].push_back(id);
}
}
last_id = new_last_id;
}
for(auto v: roots) {
bfs(v, v);
}
sort(q.begin(), q.end());
ll ans = 0LL;
ll c = 0LL;
for(auto i: q) {
if(i.second == 'A') {
c++;
} else {
ans = max(ans, c);
c--;
}
}
cout << ans << "\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 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <bits/stdc++.h> using namespace std; typedef long long ll; ll meeting_to_day[600600]; vector<ll> nbhs[600600]; vector<pair<ll, char>> q; void bfs(ll v, ll r) { vector<ll> bq; bq.push_back(v); while(bq.size()) { ll u = bq.back(); bq.pop_back(); for(auto w: nbhs[u]) { bq.push_back(w); } if(nbhs[u].size() == 0) { q.push_back({meeting_to_day[r], 'A'}); q.push_back({meeting_to_day[u], 'D'}); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll k, n; cin >> k >> n; vector<ll> roots; ll id = 0LL; for(id = 1LL; id <= n; id++) { meeting_to_day[id] = 1LL; roots.push_back(id); } ll last_id = 1; for(ll i = 2LL; i <= k; i++) { cin >> n; ll new_last_id = id; for(int j = 0LL; j < n; j++, id++) { ll a; cin >> a; meeting_to_day[id] = i; if(a == 0LL) { roots.push_back(id); } else { nbhs[last_id + a - 1].push_back(id); } } last_id = new_last_id; } for(auto v: roots) { bfs(v, v); } sort(q.begin(), q.end()); ll ans = 0LL; ll c = 0LL; for(auto i: q) { if(i.second == 'A') { c++; } else { ans = max(ans, c); c--; } } cout << ans << "\n"; return 0; } |
English