#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5+10; int n, m, d, deg[MAXN], l, kochamjulie; vector<int> e[MAXN], Q, nodes, tmp_nodes; bool vis[MAXN]; void dfs(int u) { vis[u] = true; l++; tmp_nodes.push_back(u); for (int i = 0; i < int(e[u].size()); i++) { int v = e[u][i]; if (!vis[v] && deg[v] >= d) dfs(v); } } int main() { scanf("%d%d%d", &n, &m, &d); for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); e[a].push_back(b); e[b].push_back(a); } for (int i = 1; i <= n; i++) { deg[i] = int(e[i].size()); if (deg[i] < d) Q.push_back(i); } for (int i = 0; i < int(Q.size()); i++) { int u = Q[i]; while (!e[u].empty()) { int v = e[u].back(); deg[u]--; deg[v]--; if (deg[v] == d-1) { Q.push_back(v); } e[u].pop_back(); } } for (int i = 1; i <= n; i++) { if (deg[i] >= d && !vis[i]) { l = 0; tmp_nodes.clear(); dfs(i); if (l > kochamjulie) { kochamjulie = l; nodes = tmp_nodes; } } } if (kochamjulie > 0) { printf("%d\n", kochamjulie); sort(nodes.begin(), nodes.end()); for (int i = 0; i < kochamjulie; i++) printf("%d ", nodes[i]); printf("\n"); } else { printf("NIE\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 60 61 62 63 64 65 66 67 68 69 70 | #include <bits/stdc++.h> using namespace std; const int MAXN = 2e5+10; int n, m, d, deg[MAXN], l, kochamjulie; vector<int> e[MAXN], Q, nodes, tmp_nodes; bool vis[MAXN]; void dfs(int u) { vis[u] = true; l++; tmp_nodes.push_back(u); for (int i = 0; i < int(e[u].size()); i++) { int v = e[u][i]; if (!vis[v] && deg[v] >= d) dfs(v); } } int main() { scanf("%d%d%d", &n, &m, &d); for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); e[a].push_back(b); e[b].push_back(a); } for (int i = 1; i <= n; i++) { deg[i] = int(e[i].size()); if (deg[i] < d) Q.push_back(i); } for (int i = 0; i < int(Q.size()); i++) { int u = Q[i]; while (!e[u].empty()) { int v = e[u].back(); deg[u]--; deg[v]--; if (deg[v] == d-1) { Q.push_back(v); } e[u].pop_back(); } } for (int i = 1; i <= n; i++) { if (deg[i] >= d && !vis[i]) { l = 0; tmp_nodes.clear(); dfs(i); if (l > kochamjulie) { kochamjulie = l; nodes = tmp_nodes; } } } if (kochamjulie > 0) { printf("%d\n", kochamjulie); sort(nodes.begin(), nodes.end()); for (int i = 0; i < kochamjulie; i++) printf("%d ", nodes[i]); printf("\n"); } else { printf("NIE\n"); } return 0; } |