#include <iostream>
constexpr size_t MAXN = 1e6;
bool has_cont[MAXN];
int main() {
size_t k, ni, n_prev, a;
int64_t unmatched_ends = 0, new_ends;
int64_t zero_count;
std::cin >> k >> n_prev;
for (size_t i = 2; i <= k; i++) {
std::cin >> ni;
zero_count = 0;
for (size_t j = 0; j < ni; j++) {
std::cin >> a;
if (a == 0) {
zero_count++;
}
has_cont[a] = true;
}
for (size_t j = 1; j <= n_prev; j++) {
if (!has_cont[j]) {
unmatched_ends++;
}
}
unmatched_ends = std::max((int64_t)0, unmatched_ends - zero_count);
for (size_t j = 0; j <= n_prev; j++) {
has_cont[j] = false;
}
n_prev = ni;
}
unmatched_ends += n_prev;
std::cout << unmatched_ends << '\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 | #include <iostream> constexpr size_t MAXN = 1e6; bool has_cont[MAXN]; int main() { size_t k, ni, n_prev, a; int64_t unmatched_ends = 0, new_ends; int64_t zero_count; std::cin >> k >> n_prev; for (size_t i = 2; i <= k; i++) { std::cin >> ni; zero_count = 0; for (size_t j = 0; j < ni; j++) { std::cin >> a; if (a == 0) { zero_count++; } has_cont[a] = true; } for (size_t j = 1; j <= n_prev; j++) { if (!has_cont[j]) { unmatched_ends++; } } unmatched_ends = std::max((int64_t)0, unmatched_ends - zero_count); for (size_t j = 0; j <= n_prev; j++) { has_cont[j] = false; } n_prev = ni; } unmatched_ends += n_prev; std::cout << unmatched_ends << '\n'; } |
English