The main idea: there is a person strange people want to pave the road, this person wants to put each ring on the stone, but the stone can not be repeatedly paved, if repeated paving, this side even if the damage
Ask this person how many sides to damage, how many sides can not be paved with stone
Problem-solving ideas: no stone-paved side must be a bridge, because the bridge does not belong to any one of the ring
Then judge how many sides will conflict, first of all, a ring words must be point-double connectivity, but point-double connectivity is not necessarily a ring, so this to judge.
A normal ring is to meet the number of edges = points, if the number of sides is more than a point, prove that the ring is divided into at least three rings (one of the outermost ring, two sub-rings), it can be seen that the three rings each side of a conflict
So as long as the number of edges > points is satisfied, all the side conflicts of this ring can be proved
#include <cstdio>#include <cstring>#include <vector>using namespace STD;#define N 10010#define M 200010#define MIN (a) < (b)? (a): (b))structedge{intFrom, to, Next, id; Edge () {} Edge (intFromintTo): From, to (to) {}}e[m];intN, M, tot, Dfs_clock, Bnum, bcc_cnt, top;intHead[n], Pre[n],Stack[M], low[n], num[n]; vector<int>Edge[n];BOOLVis[n];voidAddedge (intUintV) {e[tot].from = u; E[tot].to = v; E[tot].next = Head[u]; E[tot].id = tot; Head[u] = tot++; u = u ^ v; v = u ^ v; u = v ^ u; E[tot].from = u; E[tot].to = v; E[tot].next = Head[u]; E[tot].id = tot; 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); }}voidDfsintUintFA) {Pre[u] = low[u] = ++dfs_clock; for(inti = Head[u]; I! =-1; i = e[i].next) {intv = e[i].to;if(!pre[v]) {Stack[++top] = e[i].id; DFS (v, u); Low[u] = min (Low[u], low[v]);if(Low[v] >= Pre[u]) {bcc_cnt++; Edge[bcc_cnt].clear ();intx, id; while(1) {id =Stack[top--]; Edge[bcc_cnt].push_back (ID); x = E[id].from;if(x = = u) Break; }if(Low[v] > Pre[u]) bnum++; } }Else if(Pre[v] < Pre[u] && v! = FA) {Low[u] = min (Low[u], pre[v]);Stack[++top] = e[i].id; } }}voidSolve () {memset(Pre,0,sizeof(pre)); Dfs_clock = bcc_cnt = Bnum = top =0; for(inti =0; I < n; i++)if(!pre[i]) DFS (i,-1);intAns =0; for(inti =1; I <= bcc_cnt; i++) { for(intj =0; J < N; J + +) Vis[j] =false;intSize = Edge[i].size (), CNT =0; for(intj =0; J < size; J + +) {if(!vis[e[edge[i][j]].from]) {Vis[e[edge[i][j]].from] =true; cnt++; }if(!vis[e[edge[i][j]].to]) {Vis[e[edge[i][j]].to] =true; cnt++; } }if(Size > cnt) ans + = size; }printf("%d%d\n", Bnum, ans);}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.
HDU-3394 Railway (connected component + ring)