/* * mistrzostwa.cpp */ #include <cstdio> #include <unordered_set> #include <queue> using namespace std; unordered_set<int>* graph; bool* removed; int main() { int node_count, edge_count, d; scanf("%d%d%d", &node_count, &edge_count, &d); graph = new unordered_set<int>[node_count + 1]; removed = new bool[node_count + 1]; int curr_a, curr_b; for (int i = 0; i < edge_count; i++) { scanf("%d%d", &curr_a, &curr_b); graph[curr_a].insert(curr_b); graph[curr_b].insert(curr_a); } queue<int> q; for(int i = 1; i <= node_count; i++){ q.push(i); removed[i] = false; } int nodes = node_count; int curr; while(!q.empty()){ curr = q.front(); q.pop(); if(removed[curr]){ continue; } if(graph[curr].size() < d){ removed[curr] = true; nodes--; if(nodes <= d){ printf("NIE"); return 0; } for(int neigh : graph[curr]){ q.push(neigh); graph[neigh].erase(curr); } } } printf("%d\n", nodes); for(int i = 1; i <= node_count; i++){ if(!removed[i]){ printf("%d ", i); } } }
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 | /* * mistrzostwa.cpp */ #include <cstdio> #include <unordered_set> #include <queue> using namespace std; unordered_set<int>* graph; bool* removed; int main() { int node_count, edge_count, d; scanf("%d%d%d", &node_count, &edge_count, &d); graph = new unordered_set<int>[node_count + 1]; removed = new bool[node_count + 1]; int curr_a, curr_b; for (int i = 0; i < edge_count; i++) { scanf("%d%d", &curr_a, &curr_b); graph[curr_a].insert(curr_b); graph[curr_b].insert(curr_a); } queue<int> q; for(int i = 1; i <= node_count; i++){ q.push(i); removed[i] = false; } int nodes = node_count; int curr; while(!q.empty()){ curr = q.front(); q.pop(); if(removed[curr]){ continue; } if(graph[curr].size() < d){ removed[curr] = true; nodes--; if(nodes <= d){ printf("NIE"); return 0; } for(int neigh : graph[curr]){ q.push(neigh); graph[neigh].erase(curr); } } } printf("%d\n", nodes); for(int i = 1; i <= node_count; i++){ if(!removed[i]){ printf("%d ", i); } } } |