Http://codeforces.com/gym/100801/attachments
Use set to maintain the zero-in point, one edge at a time with the current pointer and the next pointer
Blogging just to commemorate the first time with set, and my lost 4 hours of youth
Ps.iterator in iterators do not change XJB
#include <cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#include<queue>#include<Set>using namespacestd;intn,m,k;Set<int>s;intf[200000],g[200000];intsum[200000],tot,sedge;structPoint {intTo,next;} e[10000000];voidAddintXinty) {e[++tot].to=y; E[tot].next=G[x]; G[X]=tot;}intMain () {Freopen ("graph.in","R", stdin); Freopen ("Graph.out","W", stdout); scanf ("%d%d%d",&n,&m,&k); for(intI=1; i<=m;i++) { intx, y; scanf ("%d%d",&x,&y); Add (x, y); Sum[y]++; } for(intI=1; i<=n;i++) { if(sum[i]==0) S.insert (i); }//cout<< "!!!!!!" <<endl; intsk=K; for(intp=1;p <=n;p++) { intflag=1; Set<int>::iterator itlast=s.end (); itlast--;//cout<< "!!!!!!" <<endl; Set<int>:: iterator Itar; //cout<<*itlast<<endl; for(Set<int>::iterator It=s.begin (); it!=itlast;it++) {//cout<< "!!!!!!" <<endl; //cout<<*it<<endl; if(f[*it]) { Set<int>::iterator tmp=it; TMP++; f[*it]=*tmp; Add (*tmp,*it); sum[*it]++; Continue; } if(f[*it]==0&&sk>0) { Set<int>::iterator tmp=it; TMP++; f[*it]=*tmp; //cout<<*tmp<< "" <<*it<<endl;Add (*tmp,*it); sum[*it]++;//cout<< "!!!!!!" <<endl;sk--; Continue; } printf ("%d",*it); Itar=it; Flag=0; Break; } if(flag) {Set<int>::iterator itlast=s.end (); itlast--; printf ("%d",*itlast); intx=*Itlast; S.erase (S.begin (), S.find (x)); S.erase (x); for(inttemp=g[x];temp;temp=E[temp].next) {Sum[e[temp].to]--; if(sum[e[temp].to]==0) S.insert (e[temp].to); } } Else { intx=*Itar; S.erase (S.begin (), S.find (x)); S.erase (x); for(inttemp=g[x];temp;temp=E[temp].next) {Sum[e[temp].to]--; if(sum[e[temp].to]==0) S.insert (e[temp].to); } } } intans=0; for(intI=1; i<=n;i++) { if(F[i]) ans++; } cout<<endl<<ans<<Endl; for(intI=1; i<=n;i++) if(F[i]) printf ("%d%d\n", F[i],i); return 0;}
Gym 100801G Graph topology sequencing