Gym 100801G Graph topology sequencing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.