//* C++11////////////////////////////////////////////////////////////////////////////////////////// #include <array> #include <unordered_map> //*//////////////////////////////////////////////////////////////////////////////////////////////// #include <fstream> #include <iostream> #include <iomanip> #include <algorithm> #include <set> #include <queue> #include <map> #include <stack> #include <cmath> #include <cstring> #include <bitset> ////////////////////////////////////////////////////////////////////////////////////////////////// #define P(i,a) for(int i=0;i<a;i++) #define P2(i,a,b) for (int i=a;i<b;i++) #define PR(i,a) for (int i=a-1;i>=0;i--) #define PR2(i,a,b) for (int i=b-1;i>=a;i--) #define FOREACH(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();i++) #define s size() #define VI vector<int> #define PB(a) push_back(a) #define PII pair<int,int> #define PLL pair<long long,long long> #define st first #define nd second #define ld long double #define ll long long #define MP make_pair #define MT make_tuple #define A(a) a.begin(),a.end() #define cmp_g(t) greater<t> #define inf numeric_limits<int>::max() #define llinf numeric_limits<long long>::max() #define troj tuple <int,int,int> #define czwor tuple <int,int,int,int> #define G(a,b) get<a>(b) #define C(a,siz) memset(a,0, siz*sizeof(a[0])) ////////////////////////////////////////////////////////////////////////////////////////////////// //#define DEBUG ////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef DEBUG #define D(a) cerr<<#a<<"="<<a<<"\n" #define D2(a,b) cerr<<#a<<"="<<a<<" , "; D(b); #define D3(a,b,c) cerr<<#a<<"="<<a<<" , "; D2(b,c); #define DP(a) cerr<<#a<<"=["<<a.st<<","<<a.nd<<"]\n"; #define out(a,siz) cerr<<#a<<" [";cerr<<a[0];P2(i,1,siz)cerr<<","<<a[i];cerr<<"]\n"; #define out_it(a) cerr<<#a<<" ["; FOREACH(it69,a){cerr <<" "<<*it69<<" ,";}cerr<<"]\n"; #define out_itP(a) cerr<<#a<<" ["; FOREACH(it69,a){cerr <<" ["<<(*it69).st<<","<<(*it69).nd<<"] ,";}cerr<<"]\n"; #else #define D(a) (void(0)) #define D2(a,b) (void(0)) #define D3(a,b,c) (void(0)) #define DP(a) (void(0)) #define out(a,siz) (void(0)) #define out_it(a) (void(0)) #define out_itP(a) (void(0)) #endif ////////////////////////////////////////////////////////////////////////////////////////////////// //#define READ_FILE ////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef READ_FILE #define pre(a) fstream in; in.open(a); #define cin in #else #define pre(a) (void(0)) #endif ////////////////////////////////////////////////////////////////////////////////////////////////// using namespace std; const int N=200*1000+100; VI kraw[N]; int wych[N]; int done[N]; multiset<PII> myset; VI lista[N]; int last=1; void dfs(int num,int kol) { if (done[num]!=0){return;} lista[kol].PB(num); done[num]=kol; FOREACH(it,kraw[num]) {dfs(*it,kol);} } int usun(int num) { FOREACH(it,kraw[num]) { auto iter=(myset.find(MP(wych[*it],*it))); if (iter==myset.end()){continue;} PII akt=*iter; myset.erase(akt); wych[*it]--; akt.st--; myset.insert(akt); } } int main() { pre("mis1005.in"); ios_base::sync_with_stdio(0); int ile,m,d,a,b; cin >>ile>>m>>d; P(i,m) { cin >>a>>b; a--; b--; kraw[a].PB(b); kraw[b].PB(a); wych[a]++; wych[b]++; } P(i,ile) {myset.insert(MP(wych[i],i));} out_itP(myset); P(i,ile) { PII akt=*myset.begin(); if (akt.st<d) { myset.erase(akt); usun(akt.nd); out_itP(myset); } else { break; } } if (myset.s==0){cout <<"NIE"; return 0;} fill(done,done+N,-1); FOREACH(it,myset) {done[(*it).nd]=0;} P(i,ile) { dfs(i,last++); } out(done,ile); int maxi=0; P(i,ile+1) {maxi=max(maxi,(int)lista[i].s);} cout <<maxi<<"\n"; P(i,ile+1) { if (lista[i].s==maxi) {P(q,lista[i].s){cout <<1+lista[i][q]<<" ";}} } }
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | //* C++11////////////////////////////////////////////////////////////////////////////////////////// #include <array> #include <unordered_map> //*//////////////////////////////////////////////////////////////////////////////////////////////// #include <fstream> #include <iostream> #include <iomanip> #include <algorithm> #include <set> #include <queue> #include <map> #include <stack> #include <cmath> #include <cstring> #include <bitset> ////////////////////////////////////////////////////////////////////////////////////////////////// #define P(i,a) for(int i=0;i<a;i++) #define P2(i,a,b) for (int i=a;i<b;i++) #define PR(i,a) for (int i=a-1;i>=0;i--) #define PR2(i,a,b) for (int i=b-1;i>=a;i--) #define FOREACH(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();i++) #define s size() #define VI vector<int> #define PB(a) push_back(a) #define PII pair<int,int> #define PLL pair<long long,long long> #define st first #define nd second #define ld long double #define ll long long #define MP make_pair #define MT make_tuple #define A(a) a.begin(),a.end() #define cmp_g(t) greater<t> #define inf numeric_limits<int>::max() #define llinf numeric_limits<long long>::max() #define troj tuple <int,int,int> #define czwor tuple <int,int,int,int> #define G(a,b) get<a>(b) #define C(a,siz) memset(a,0, siz*sizeof(a[0])) ////////////////////////////////////////////////////////////////////////////////////////////////// //#define DEBUG ////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef DEBUG #define D(a) cerr<<#a<<"="<<a<<"\n" #define D2(a,b) cerr<<#a<<"="<<a<<" , "; D(b); #define D3(a,b,c) cerr<<#a<<"="<<a<<" , "; D2(b,c); #define DP(a) cerr<<#a<<"=["<<a.st<<","<<a.nd<<"]\n"; #define out(a,siz) cerr<<#a<<" [";cerr<<a[0];P2(i,1,siz)cerr<<","<<a[i];cerr<<"]\n"; #define out_it(a) cerr<<#a<<" ["; FOREACH(it69,a){cerr <<" "<<*it69<<" ,";}cerr<<"]\n"; #define out_itP(a) cerr<<#a<<" ["; FOREACH(it69,a){cerr <<" ["<<(*it69).st<<","<<(*it69).nd<<"] ,";}cerr<<"]\n"; #else #define D(a) (void(0)) #define D2(a,b) (void(0)) #define D3(a,b,c) (void(0)) #define DP(a) (void(0)) #define out(a,siz) (void(0)) #define out_it(a) (void(0)) #define out_itP(a) (void(0)) #endif ////////////////////////////////////////////////////////////////////////////////////////////////// //#define READ_FILE ////////////////////////////////////////////////////////////////////////////////////////////////// #ifdef READ_FILE #define pre(a) fstream in; in.open(a); #define cin in #else #define pre(a) (void(0)) #endif ////////////////////////////////////////////////////////////////////////////////////////////////// using namespace std; const int N=200*1000+100; VI kraw[N]; int wych[N]; int done[N]; multiset<PII> myset; VI lista[N]; int last=1; void dfs(int num,int kol) { if (done[num]!=0){return;} lista[kol].PB(num); done[num]=kol; FOREACH(it,kraw[num]) {dfs(*it,kol);} } int usun(int num) { FOREACH(it,kraw[num]) { auto iter=(myset.find(MP(wych[*it],*it))); if (iter==myset.end()){continue;} PII akt=*iter; myset.erase(akt); wych[*it]--; akt.st--; myset.insert(akt); } } int main() { pre("mis1005.in"); ios_base::sync_with_stdio(0); int ile,m,d,a,b; cin >>ile>>m>>d; P(i,m) { cin >>a>>b; a--; b--; kraw[a].PB(b); kraw[b].PB(a); wych[a]++; wych[b]++; } P(i,ile) {myset.insert(MP(wych[i],i));} out_itP(myset); P(i,ile) { PII akt=*myset.begin(); if (akt.st<d) { myset.erase(akt); usun(akt.nd); out_itP(myset); } else { break; } } if (myset.s==0){cout <<"NIE"; return 0;} fill(done,done+N,-1); FOREACH(it,myset) {done[(*it).nd]=0;} P(i,ile) { dfs(i,last++); } out(done,ile); int maxi=0; P(i,ile+1) {maxi=max(maxi,(int)lista[i].s);} cout <<maxi<<"\n"; P(i,ile+1) { if (lista[i].s==maxi) {P(q,lista[i].s){cout <<1+lista[i][q]<<" ";}} } } |