#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
using i128 = __int128;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int k, n1;
std::cin >> k >> n1;
std::vector<int> s(n1);
std::vector<int> f(k);
for (int i = 1; i < k; i++) {
int n;
std::cin >> n;
std::vector<int> ns(n);
std::vector<bool> vis(s.size());
for (int j = 0; j < n; j++) {
int a;
std::cin >> a;
a--;
if (a >= 0) {
ns[j] = s[a];
vis[a] = true;
} else {
ns[j] = i;
}
}
for (int j = 0; j < s.size(); j++) {
if (!vis[j]) {
f[s[j]]++;
f[i]--;
}
}
s = std::move(ns);
}
for (auto x : s) {
f[x]++;
}
for (int i = 1; i < k; i++) {
f[i] += f[i - 1];
}
const int ans = *std::max_element(f.begin(), f.end());
std::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 | #include <bits/stdc++.h> using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; using i128 = __int128; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int k, n1; std::cin >> k >> n1; std::vector<int> s(n1); std::vector<int> f(k); for (int i = 1; i < k; i++) { int n; std::cin >> n; std::vector<int> ns(n); std::vector<bool> vis(s.size()); for (int j = 0; j < n; j++) { int a; std::cin >> a; a--; if (a >= 0) { ns[j] = s[a]; vis[a] = true; } else { ns[j] = i; } } for (int j = 0; j < s.size(); j++) { if (!vis[j]) { f[s[j]]++; f[i]--; } } s = std::move(ns); } for (auto x : s) { f[x]++; } for (int i = 1; i < k; i++) { f[i] += f[i - 1]; } const int ans = *std::max_element(f.begin(), f.end()); std::cout << ans << "\n"; return 0; } |
English