#include <cstdio> int main() { int n; scanf("%d", &n); int conn[n][n]; int connected[n]; int no_final = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { conn[i][j] = 0; } connected[i] = 0; } connected[0] = 1; int l_c = 0; int l_c_0; for (int i = 0; i < n; ++i) { int l_p; scanf("%i", &l_p); if (i == 0) l_c_0 = l_p; else if (connected[i] == 1) l_c += l_p; for (int j = 0; j < l_p; ++j) { int nu_to; scanf("%i", &nu_to); if (connected[i] == 1) connected[nu_to - 1] = 1; } } int score; if (l_c_0 == 0) score = 1; else score = l_c + (l_c % l_c_0); printf("%d", score); 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 | #include <cstdio> int main() { int n; scanf("%d", &n); int conn[n][n]; int connected[n]; int no_final = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { conn[i][j] = 0; } connected[i] = 0; } connected[0] = 1; int l_c = 0; int l_c_0; for (int i = 0; i < n; ++i) { int l_p; scanf("%i", &l_p); if (i == 0) l_c_0 = l_p; else if (connected[i] == 1) l_c += l_p; for (int j = 0; j < l_p; ++j) { int nu_to; scanf("%i", &nu_to); if (connected[i] == 1) connected[nu_to - 1] = 1; } } int score; if (l_c_0 == 0) score = 1; else score = l_c + (l_c % l_c_0); printf("%d", score); return 0; } |