Uoj ur#9 App Manager

Source: Internet
Author: User

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

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.