#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=(a);i<=(b);++i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define SORT(X) sort(X.begin(),X.end()) #define fi first #define se second vector<int> V[200200]; int S[200200]; int d; int Op[200200]; void pop(int u){ Op[u] = 1; for(auto v : V[u]){ S[v]--; if(S[v] < d && Op[v] == 0) pop(v); } } vector<int> Ans; vector<int> Pro; void cnt(int u){ Op[u] = 1; for(auto v : V[u]){ if(Op[v] == 0) cnt(v); } Pro.pb(u); } int main () { int n,m; scanf("%d%d%d",&n,&m,&d); FOR(i,m){ int a,b; scanf("%d%d",&a,&b); V[a].pb(b); V[b].pb(a); S[a]++; S[b]++; } FORI(i,n){ if(S[i] < d && Op[i] == 0) pop(i); } FORI(i,n){ if(Op[i] == 0){ Pro.clear(); cnt(i); if(Pro.size() > Ans.size()){ Ans = Pro; } } } SORT(Ans); if(Ans.size() == 0){ printf("NIE\n"); }else{ printf("%d\n", SZ(Ans)); for(auto a : Ans){ printf("%d ", a); } printf("\n"); } }
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 | #include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=(a);i<=(b);++i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define SORT(X) sort(X.begin(),X.end()) #define fi first #define se second vector<int> V[200200]; int S[200200]; int d; int Op[200200]; void pop(int u){ Op[u] = 1; for(auto v : V[u]){ S[v]--; if(S[v] < d && Op[v] == 0) pop(v); } } vector<int> Ans; vector<int> Pro; void cnt(int u){ Op[u] = 1; for(auto v : V[u]){ if(Op[v] == 0) cnt(v); } Pro.pb(u); } int main () { int n,m; scanf("%d%d%d",&n,&m,&d); FOR(i,m){ int a,b; scanf("%d%d",&a,&b); V[a].pb(b); V[b].pb(a); S[a]++; S[b]++; } FORI(i,n){ if(S[i] < d && Op[i] == 0) pop(i); } FORI(i,n){ if(Op[i] == 0){ Pro.clear(); cnt(i); if(Pro.size() > Ans.size()){ Ans = Pro; } } } SORT(Ans); if(Ans.size() == 0){ printf("NIE\n"); }else{ printf("%d\n", SZ(Ans)); for(auto a : Ans){ printf("%d ", a); } printf("\n"); } } |