The main idea: to give an image, any two points can reach each other, now requires you to turn this non-direction diagram into a map, and change any two points can be reached each other
Problem-Solving ideas: Bridge words must be to keep the two-way, so you can in the DFS when the bridge mark out, by the way in the DFS mark the use of which side can be
#include <cstdio>#include <cstring>#define N 1010#define M 1000010#define MIN (a) < (b)? (a): (b))structedge{intFrom, to, next, flag;} E[M];intHead[n], Pre[n], lowlink[n];intTot, N, M, Dfs_clock;voidAddedge (intUintV) {e[tot].from = u; E[tot].to = v; E[tot].flag =0; E[tot].next = Head[u]; Head[u] = tot++;}voidInit () {memset(Head,-1,sizeof(head)); tot =0;intU, v; for(inti =0; I < m; i++) {scanf("%d%d", &u, &v); Addedge (U, v); Addedge (V, u); }}voidDfsintUintFA) {Pre[u] = lowlink[u] = ++dfs_clock;intV for(inti = Head[u]; I! =-1; i = e[i].next) {v = e[i].to;if(E[i].flag)Continue; E[i].flag =1; E[i ^1].flag =-1;if(!pre[v]) {DFS (V, u); Lowlink[u] = min (Lowlink[u], lowlink[v]);if(Lowlink[v] > Pre[u]) E[i ^1].flag =1; }Else if(v! = FA) Lowlink[u] = min (Lowlink[u], pre[v]); }}intCAS =1;voidSolve () {memset(Pre,0,sizeof(pre)); Dfs_clock =0; for(inti =1; I <= N; i++)if(!pre[i]) DFS (i,-1);printf("%d\n\n", cas++);intU, v; for(inti =0; i < tot; i++) {u = e[i].from; v = e[i].to;if(E[i].flag = =1)printf("%d%d\n", u, v); }printf("#\n");}intMain () { while(scanf("%d%d", &n, &m)! = EOF && n + m) {init (); Solve (); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ-1515 Street Directions (non-direction graph variable map)