/*the problem with the dichotomy is to determine the non-connected edges if we're left with the possibility of connectivity.*/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 210using namespacestd;intN,num,head[maxn],g[maxn][maxn],ans,f[maxn],match[maxn],sum,ei;structans{intx, y;} AN[MAXN*MAXN];structnode{intU,v,pre;} E[MAXN*MAXN];intcmpConstAns &a,ConstAns &b) { returna.x<b.x;}intinit () {intx=0;Chars=GetChar (); while(s<'0'|| S>'9') s=GetChar (); while(s>='0'&&s<='9') {x=x*Ten+s-'0'; s=GetChar ();} returnx;}voidADD (int from,intTo ) {num++; E[NUM].U= from; E[NUM].V=to ; E[num].pre=head[ from]; head[ from]=num;}intDfs (intk) { for(intI=head[k];i;i=e[i].pre)if(f[e[i].v]==0&&i!=ei) {F[E[I].V]=1; if(match[e[i].v]==0||Dfs (MATCH[E[I].V])) {MATCH[E[I].V]=K; return 1; } } return 0;}intMain () {n=init (); intu,v; while(1) {u=init (); v=init (); if(u==0&&v==0) Break; G[U][V]=1; } for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) if(g[i][j]==0) Add (I,J); for(intI=1; i<=n;i++) {memset (F,0,sizeof(f)); Ans+=Dfs (i); } if(ans!=N) {printf ("none\n"); return 0; } for(intI=1; i<=num;i++) {memset (match,0,sizeof(match)); Ans=0; for(intj=1; j<=n;j++) {memset (F,0,sizeof(f)); Ei=i; Ans+=Dfs (j); } if(ans!=n) {sum++; an[sum].x=e[i].u; An[sum].y=e[i].v; } } if(sum==0) {printf ("none\n"); return 0; } sort ( an+1, an+1+sum,cmp); for(intI=1; i<=sum;i++) printf ("%d%d\n", AN[I].X,AN[I].Y); return 0;}
Codevs 1222 Letter and envelope issues