Topic Portal
The main idea is to give you a mixed map (both to the side and there is no direction), for each of the non-side, u-v, ask to delete u->v, or delete v->u that can make the new diagram strong connectivity. (Ensure the data has a solution).
The first few data points of this problem are sent.
Enumerate each edge, first remove it, traverse the graph, if you can reach all points, that is, strong connectivity.
For example, remove the u->v, in fact, as long as DFS (U), to determine whether the V can be reached.
Can be deleted directly, otherwise delete the other side, after the deletion because the graph strong connectivity, so after the operation has no effect.
Code
#include <cstdio>#include<cstring>using namespacestd;intRead () {CharC while(C=getchar (),c<'0'|| C>'9'); intx=c-'0'; while(C=getchar (), c>='0'&&c<='9') x=x*Ten+c-'0'; returnx;}Const intmaxn=5005;intn,m,ide[maxn<<1],VIS[MAXN];inthead[maxn],to[maxn<<1],nxt[maxn<<1],cnt;structnode{intX,y,o,d;} EDGE[MAXN];voidAddintXinty) {to[cnt]=y; NXT[CNT]=Head[x]; HEAD[X]=CNT; CNT++;}voidDfsintNow ) {Vis[now]=1; for(inti=head[now];i!=-1; i=Nxt[i]) { if(!ide[i]&&!Vis[to[i]]) {DFS (to[i]); } }}intMain () {N=read (), m=read (); memset (Head,-1,sizeofhead); for(intI=1; i<=m;i++){ intX=read (), Y=read (), o=read (); Add (x, y);if(!o) Add (y,x); Edge[i]= (node) {x,y,o,cnt-1}; } for(intI=1; i<=m;i++){ if(EDGE[I].O) {Puts ("0");Continue;} memset (Vis,0,sizeofvis); IDE[EDGE[I].D]=1; DFS (EDGE[I].Y); if(vis[edge[i].x]) {puts ("0");Continue; } Else{IDE[EDGE[I].D]=0; IDE[EDGE[I].D-1]=1; } puts ("1");Continue; } return 0;}
Uoj ur#9 App Manager