#include <cstdio>
// starting from day 1
int first_index_per_day[500000];
int last_index_per_day[500000];
struct Spotkanie
{
Spotkanie* parent;
int people;
Spotkanie() : parent(nullptr), people(0) { }
};
Spotkanie spotkania[1000000];
int main()
{
int k, n;
scanf("%d%d", &k, &n);
first_index_per_day[0] = 0;
last_index_per_day[0] = n - 1;
int next_index = n;
for (int t=2; t<=k; ++t) {
first_index_per_day[t-1] = next_index;
scanf("%d", &n);
for (int j=0; j<n; ++j) {
int a; scanf("%d", &a);
if (a > 0) {
int parent_index = first_index_per_day[t-2] + a - 1;
spotkania[next_index].parent = &spotkania[parent_index];
}
next_index++;
}
last_index_per_day[t-1] = next_index - 1;
}
int last_index = next_index - 1;
for (int i=last_index; i>=0; --i) {
if (!spotkania[i].people) {
spotkania[i].people = 1;
}
if (spotkania[i].parent) {
spotkania[i].parent->people += spotkania[i].people;
}
}
/*
// kontrolne wypisywanie
for (int t=0; t<k; ++t) {
printf("DAY %d:\n", t+1);
for (int i=first_index_per_day[t]; i<=last_index_per_day[t]; ++i) {
if (spotkania[i].parent) {
printf("spotkanie #%d jest kontynuacją #%ld: %d\n", i, spotkania[i].parent - spotkania, spotkania[i].people);
} else {
printf("spotkanie #%d nie jest kontynuacją: %d\n", i, spotkania[i].people);
}
}
}
*/
int max_total_people = 0;
for (int t=0; t<k; ++t) {
int total_people = 0;
for (int i=first_index_per_day[t]; i<=last_index_per_day[t]; ++i) {
total_people += spotkania[i].people;
}
if (total_people > max_total_people) {
max_total_people = total_people;
}
}
printf("%d\n", max_total_people);
}
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 | #include <cstdio> // starting from day 1 int first_index_per_day[500000]; int last_index_per_day[500000]; struct Spotkanie { Spotkanie* parent; int people; Spotkanie() : parent(nullptr), people(0) { } }; Spotkanie spotkania[1000000]; int main() { int k, n; scanf("%d%d", &k, &n); first_index_per_day[0] = 0; last_index_per_day[0] = n - 1; int next_index = n; for (int t=2; t<=k; ++t) { first_index_per_day[t-1] = next_index; scanf("%d", &n); for (int j=0; j<n; ++j) { int a; scanf("%d", &a); if (a > 0) { int parent_index = first_index_per_day[t-2] + a - 1; spotkania[next_index].parent = &spotkania[parent_index]; } next_index++; } last_index_per_day[t-1] = next_index - 1; } int last_index = next_index - 1; for (int i=last_index; i>=0; --i) { if (!spotkania[i].people) { spotkania[i].people = 1; } if (spotkania[i].parent) { spotkania[i].parent->people += spotkania[i].people; } } /* // kontrolne wypisywanie for (int t=0; t<k; ++t) { printf("DAY %d:\n", t+1); for (int i=first_index_per_day[t]; i<=last_index_per_day[t]; ++i) { if (spotkania[i].parent) { printf("spotkanie #%d jest kontynuacją #%ld: %d\n", i, spotkania[i].parent - spotkania, spotkania[i].people); } else { printf("spotkanie #%d nie jest kontynuacją: %d\n", i, spotkania[i].people); } } } */ int max_total_people = 0; for (int t=0; t<k; ++t) { int total_people = 0; for (int i=first_index_per_day[t]; i<=last_index_per_day[t]; ++i) { total_people += spotkania[i].people; } if (total_people > max_total_people) { max_total_people = total_people; } } printf("%d\n", max_total_people); } |
English