#include <bits/stdc++.h> using namespace std; int d, n, L[200000], S[200000]; queue<int> Q; vector<int> D[200000], DS[200000]; int main() { int a, b, k, m, mk, mm; scanf("%d %d %d", &n, &m, &d); while (m--) { scanf("%d %d", &a, &b); --a; --b; D[a].push_back(b); D[b].push_back(a); ++L[a]; ++L[b]; } for (int i = 0; i < n; ++i) { if (L[i] < d) { Q.push(i); } } while (!Q.empty()) { a = Q.front(); Q.pop(); if (L[a] == 0) { continue; } for (auto i: D[a]) { if (L[i] > 0) { --L[a]; --L[i]; if (L[i] < d) { Q.push(i); } } } } for (int i = 0; i < n; ++i) { if (L[i] == 0) { continue; } for (auto j: D[i]) { if (L[j] > 0) { DS[i].push_back(j); } } } m = mk = mm = 0; for (int i = 0; i < n; ++i) { if (!L[i] || S[i]) { continue; } k = 0; ++m; S[i] = m; Q.push(i); while (!Q.empty()) { a = Q.front(); Q.pop(); ++k; for (auto j: DS[a]) { if (!S[j]) { S[j] = m; Q.push(j); } } } if (k > mk) { mk = k; mm = m; } } if (!mk) { puts("NIE"); return 0; } printf("%d\n", mk); for (int i = 0; i < n; ++i) { if (S[i] == mm) { printf("%d ", i + 1); } } puts(""); 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #include <bits/stdc++.h> using namespace std; int d, n, L[200000], S[200000]; queue<int> Q; vector<int> D[200000], DS[200000]; int main() { int a, b, k, m, mk, mm; scanf("%d %d %d", &n, &m, &d); while (m--) { scanf("%d %d", &a, &b); --a; --b; D[a].push_back(b); D[b].push_back(a); ++L[a]; ++L[b]; } for (int i = 0; i < n; ++i) { if (L[i] < d) { Q.push(i); } } while (!Q.empty()) { a = Q.front(); Q.pop(); if (L[a] == 0) { continue; } for (auto i: D[a]) { if (L[i] > 0) { --L[a]; --L[i]; if (L[i] < d) { Q.push(i); } } } } for (int i = 0; i < n; ++i) { if (L[i] == 0) { continue; } for (auto j: D[i]) { if (L[j] > 0) { DS[i].push_back(j); } } } m = mk = mm = 0; for (int i = 0; i < n; ++i) { if (!L[i] || S[i]) { continue; } k = 0; ++m; S[i] = m; Q.push(i); while (!Q.empty()) { a = Q.front(); Q.pop(); ++k; for (auto j: DS[a]) { if (!S[j]) { S[j] = m; Q.push(j); } } } if (k > mk) { mk = k; mm = m; } } if (!mk) { puts("NIE"); return 0; } printf("%d\n", mk); for (int i = 0; i < n; ++i) { if (S[i] == mm) { printf("%d ", i + 1); } } puts(""); return 0; } |