#include <iostream> #include <vector> #include <set> #include <cstdio> #include <algorithm> using namespace std; vector<int> A[200001]; int NOWY[200001],KRAW[200001]; int n, m,d, i, j, temp=0,licznik = 1,wyn=0,w = 0,k,v,w1,w2; void dfs2(int v) { NOWY[v] = licznik; temp++; for(int i = 0; i< A[v].size(); ++i){ int w = A[v][i]; if(NOWY[w] == 0) dfs2(w); } } void dfs1(int v) { NOWY[v] = -1; for(int i = 0; i< A[v].size(); ++i){ int w = A[v][i]; if(NOWY[w] == 0){ KRAW[w]--; if(KRAW[w] < d) dfs1(w); } } } int main() { ios_base::sync_with_stdio(0); scanf("%d %d %d", &n,&m,&d); for(i=1;i<=m;++i) { scanf("%d %d", &w1,&w2); A[w1].push_back(w2); A[w2].push_back(w1); } for( j=1; j<=n ;++j) KRAW[j] = A[j].size(); for( j=1; j<=n ;++j) if(NOWY[j] == 0) if(KRAW[j] < d) dfs1(j); for( j=1; j<=n ;++j) if(NOWY[j]==0){ temp = 0; dfs2(j); if(temp > wyn) { wyn = temp; w = licznik; } licznik++; } if(wyn > 1) { printf("%d\n", wyn); for( j=1; j<=n ;++j) if(NOWY[j]==w) printf("%d ", j); } 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 | #include <iostream> #include <vector> #include <set> #include <cstdio> #include <algorithm> using namespace std; vector<int> A[200001]; int NOWY[200001],KRAW[200001]; int n, m,d, i, j, temp=0,licznik = 1,wyn=0,w = 0,k,v,w1,w2; void dfs2(int v) { NOWY[v] = licznik; temp++; for(int i = 0; i< A[v].size(); ++i){ int w = A[v][i]; if(NOWY[w] == 0) dfs2(w); } } void dfs1(int v) { NOWY[v] = -1; for(int i = 0; i< A[v].size(); ++i){ int w = A[v][i]; if(NOWY[w] == 0){ KRAW[w]--; if(KRAW[w] < d) dfs1(w); } } } int main() { ios_base::sync_with_stdio(0); scanf("%d %d %d", &n,&m,&d); for(i=1;i<=m;++i) { scanf("%d %d", &w1,&w2); A[w1].push_back(w2); A[w2].push_back(w1); } for( j=1; j<=n ;++j) KRAW[j] = A[j].size(); for( j=1; j<=n ;++j) if(NOWY[j] == 0) if(KRAW[j] < d) dfs1(j); for( j=1; j<=n ;++j) if(NOWY[j]==0){ temp = 0; dfs2(j); if(temp > wyn) { wyn = temp; w = licznik; } licznik++; } if(wyn > 1) { printf("%d\n", wyn); for( j=1; j<=n ;++j) if(NOWY[j]==w) printf("%d ", j); } else printf("NIE"); return 0; } |