#ifdef LOC
#include "debuglib.hpp"
#else
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define deb(...)
#define DBP(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x) for (auto& a : (x))
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cout << fixed << setprecision(12);
int k, n1;
cin >> k >> n1;
vector<vector<int>> par(k), cnt(k);
par[0].resize(n1, -1);
cnt[0].resize(n1);
rep(i, 1, k) {
int ni; cin >> ni;
par[i].resize(ni);
cnt[i].resize(ni);
each(p, par[i]) cin >> p, p--;
}
int ans = 0;
for (int i = k-1; i >= 0; i--) {
int alt = 0;
rep(j, 0, sz(par[i])) {
int c = max(cnt[i][j], 1);
alt += c;
if (par[i][j] != -1) {
cnt[i-1][par[i][j]] += c;
}
}
ans = max(ans, alt);
}
cout << ans << '\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 | #ifdef LOC #include "debuglib.hpp" #else #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define deb(...) #define DBP(...) #endif using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int, int>; #define pb push_back #define mp make_pair #define x first #define y second #define rep(i, b, e) for (int i = (b); i < (e); i++) #define each(a, x) for (auto& a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) int((x).size()) int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(12); int k, n1; cin >> k >> n1; vector<vector<int>> par(k), cnt(k); par[0].resize(n1, -1); cnt[0].resize(n1); rep(i, 1, k) { int ni; cin >> ni; par[i].resize(ni); cnt[i].resize(ni); each(p, par[i]) cin >> p, p--; } int ans = 0; for (int i = k-1; i >= 0; i--) { int alt = 0; rep(j, 0, sz(par[i])) { int c = max(cnt[i][j], 1); alt += c; if (par[i][j] != -1) { cnt[i-1][par[i][j]] += c; } } ans = max(ans, alt); } cout << ans << '\n'; } |
English