刚刚弄明白了强连通和双连通,我好菜啊。。TUT
两道差不多的题目,POJ - 3177 和计蒜客的Islands
poj-3177 给出很多边,问添加最少多少条边成为一个双连通
Islands 变成强连通
强连通:图中任意两个节点可以相互通达
双连通:图中任意两个节点之间都有两条路
POJ-3177 跑一遍Tarjan 所有的双连通块看做一个点,将整个图看做一棵树,把整棵树的叶子节点连接起来,就是答案了。
AC代码
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=5123;
struct node
{
int v,next;
bool cut;
} eage[N*10];
int head[N];
int dfn[N],low[N],Belong[N];
int du[N],Instack[N];
int Stack[N];
int tot;
int Index,top;
int block;
int n,m;
void Add(int u,int v)
{
eage[top].v=v;
eage[top].cut=0;
eage[top].next=head[u];
head[u]=top++;
}