割边 - 模板
作者:互联网
#include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define MAXN 1000010 #define MAXM 5010 inline int read() { int x = 0,ff = 1;char ch = getchar(); while(!isdigit(ch)) { if(ch == '-') ff = -1; ch = getchar(); } while(isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * ff; } int n,m,ti = 0,top = 0,dfn[MAXN],low[MAXN],cut[MAXN]; int lin[MAXN],tot = 1; struct edge { int x,y,next; }e[MAXN]; inline void add(int xx,int yy) { e[++tot].y = yy; e[tot].x = xx; e[tot].next = lin[xx]; lin[xx] = tot; } void Tarjan(int x,int bridge) { dfn[x] = low[x] = ++ti; for(int i = lin[x],y;i;i = e[i].next) { if(!dfn[y = e[i].y]) { Tarjan(y,i); low[x] = min(low[x],low[y]); if(low[y] > dfn[x]) cut[i] = cut[i ^ 1] = true; } else if(i != (bridge ^ 1)) low[x] = min(low[x],dfn[y]); } } int main() { n = read(); m = read(); for(int i = 1;i <= m;++i) { int x,y; x = read(); y = read(); add(x,y); add(y,x); } for(int i = 1;i <= n;++i) if(!dfn[i]) Tarjan(i,0); for(int i = 2;i <= tot;i += 2) if(cut[i] == true) printf("%d %d\n",e[i].x,e[i].y);return 0; }
标签:ch,int,割边,read,isdigit,getchar,模板,define 来源: https://www.cnblogs.com/AK-ls/p/10388746.html