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
|
using namespace std; namespace Debug{ Tp I void _debug(Cn char* f,Ty t){cerr<<f<<'='<<t<<endl;} Ts I void _debug(Cn char* f,Ty x,Ar... y){W(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);} Tp ostream& operator<<(ostream& os,Cn vector<Ty>& V){os<<"[";for(Cn auto& vv:V) os<<vv<<",";os<<"]";return os;} #define gdb(...) _debug(#__VA_ARGS__,__VA_ARGS__) }using namespace Debug; namespace FastIO{ #define FS 100000 #define tc() (FA==FB&&(FB=(FA=FI)+fread(FI,1,FS,stdin),FA==FB)?EOF:*FA++) #define pc(c) (FC==FE&&(clear(),0),*FC++=c) int OT;char oc,FI[FS],FO[FS],OS[FS],*FA=FI,*FB=FI,*FC=FO,*FE=FO+FS; I void clear() {fwrite(FO,1,FC-FO,stdout),FC=FO;} Tp I void read(Ty& x) {x=0;RI f=1;W(!isdigit(oc=tc())) f=oc^'-'?1:-1;W(x=(x<<3)+(x<<1)+(oc&15),isdigit(oc=tc()));x*=f;} Ts I void read(Ty& x,Ar&... y) {read(x),read(y...);} Tp I void write(Ty x) {x<0&&(pc('-'),x=-x);W(OS[++OT]=x%10+48,x/=10);W(OT) pc(OS[OT--]);} Tp I void writeln(Ty x) {x<0&&(pc('-'),x=-x);W(OS[++OT]=x%10+48,x/=10);W(OT) pc(OS[OT--]);pc('\n');} }using namespace FastIO; Cn int N=105,M=1e3+10,P=N*2,E=(N*N+N*2)*2,inf=2e9; int n,m,fir[P],nxt[E],son[E],w[E],tot=1,S,T,cnt,cur[P],D[P],visL[N],visR[N],gT,Mk[N],Ans,r[N]; I void Add(CI x,CI y,CI z){nxt[++tot]=fir[x],fir[x]=tot,son[tot]=y,w[tot]=z,nxt[++tot]=fir[y],fir[y]=tot,son[tot]=x,w[tot]=0;}
bitset<N> b[N]; queue<int> q; I bool Bfs(){RI i,u;W(!q.empty()) q.pop();memset(D,-1,sizeof(D)),D[S]=0,q.push(S);W(!q.empty()) for(u=q.front(),q.pop(),i=fir[u];i;i=nxt[i]) w[i]&&!~D[to]&&(q.push(to),D[to]=D[u]+1);return ~D[T];} I int Dfs(CI x,CI flow){if(x==T) return flow;RI now=flow,i,d;for(i=cur[x];i;i=nxt[i]) if(cur[x]=nxt[i],w[i]&&D[to]==D[x]+1){d=Dfs(to,min(now,w[i])),w[i]-=d,w[i^1]+=d,now-=d;if(!now) break ;}return flow-now;} I int Dinic(){RI i,X=0;W(Bfs()){for(i=1;i<=cnt;i++) cur[i]=fir[i];X+=Dfs(S,inf);}return X;} I void DFS(CI x){RI i;for(visR[x]=1,i=1;i<=n;i++) b[i][x]&&!visL[i]&&(visL[i]=1,DFS(r[i]),0);} int main(){ freopen("isolated.in","r",stdin),freopen("isolated.out","w",stdout); RI i,j,k,x,y;for(read(n,m),i=1;i<=m;i++) read(x,y),b[x][y]=1; for(k=1;k<=n;k++) for(i=1;i<=n;i++) b[i][k]&&(b[i]=b[k],0); for(S=1,cnt=(n<<11),T=++cnt,i=1;i<=n;i++) Add(S,i<<1,1),Add(i<<11,T,1); for(i=1;i<=n;i++) for(j=1;j<=n;j++) b[i][j]&&(Add(i<<1,j<<11,1),0); Ans=n-Dinic(),writeln(Ans); for(i=1;i<=n;i++) if(!w[i*4-2]) for(j=fir[i];j;j=nxt[j]) son[j]^S&&!w[j^1]&&(r[i]=son[j]/2); for(i=1;i<=n;i++) if(w[i*4]) DFS(i);for(i=1;i<=n;i++) write(!visL[i]&&visR[i]);pc('\n'); for(k=1;k<=n;write(gT-Dinic()==Ans-1),k++){ for(i=1;i<=n;i++) Mk[i]=(k^i&&!b[k][i]&&!b[i][k]); for(memset(fir,0,sizeof(fir)),tot=S=1,gT=0,cnt=(n<<11),T=++cnt,i=1;i<=n;i++) Mk[i]&&(Add(S,i<<1,1),Add(i<<11,T,1),gT++); for(i=1;i<=n;i++) for(j=1;j<=n;j++) Mk[i]&&Mk[j]&&b[i][j]&&(Add(i<<1,j<<11,1),0); }return pc('\n'),clear(),0; }
|