#include <cstdio> #include <algorithm> #include <vector> using namespace std; vector<int> sas[200005]; int st[200005],d,nr,licz[200005],naj,sp[200005]; bool byl[200005],odw[200005]; void zabij (int co) { byl[co]=1; for (vector<int>::iterator it=sas[co].begin(); it!=sas[co].end(); it++) { st[*it]--; if (!byl[*it] && st[*it]<d) zabij(*it); } } void dfs (int co) { odw[co]=1; sp[co]=nr; licz[nr]++; for (vector<int>::iterator it=sas[co].begin(); it!=sas[co].end(); it++) if (!byl[*it] && !odw[*it]) dfs(*it); } int main() { int n,m,a,b,c; scanf ("%d%d%d", &n, &m, &d); while (m--) { scanf ("%d%d", &a, &b); st[a]++; st[b]++; sas[a].push_back(b); sas[b].push_back(a); } for (a=1; a<=n; a++) if (!byl[a] && st[a]<d) zabij(a); for (a=1; a<=n; a++) if (!byl[a] && !odw[a]) { nr++; dfs(a); if (licz[nr]>naj) { naj=licz[nr]; c=nr; } } if (naj) { printf ("%d\n", naj); for (a=1; a<=n; a++) if (sp[a]==c) printf ("%d ", a); } else printf ("NIE"); 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 | #include <cstdio> #include <algorithm> #include <vector> using namespace std; vector<int> sas[200005]; int st[200005],d,nr,licz[200005],naj,sp[200005]; bool byl[200005],odw[200005]; void zabij (int co) { byl[co]=1; for (vector<int>::iterator it=sas[co].begin(); it!=sas[co].end(); it++) { st[*it]--; if (!byl[*it] && st[*it]<d) zabij(*it); } } void dfs (int co) { odw[co]=1; sp[co]=nr; licz[nr]++; for (vector<int>::iterator it=sas[co].begin(); it!=sas[co].end(); it++) if (!byl[*it] && !odw[*it]) dfs(*it); } int main() { int n,m,a,b,c; scanf ("%d%d%d", &n, &m, &d); while (m--) { scanf ("%d%d", &a, &b); st[a]++; st[b]++; sas[a].push_back(b); sas[b].push_back(a); } for (a=1; a<=n; a++) if (!byl[a] && st[a]<d) zabij(a); for (a=1; a<=n; a++) if (!byl[a] && !odw[a]) { nr++; dfs(a); if (licz[nr]>naj) { naj=licz[nr]; c=nr; } } if (naj) { printf ("%d\n", naj); for (a=1; a<=n; a++) if (sp[a]==c) printf ("%d ", a); } else printf ("NIE"); return 0; } |