hdu 4587

求割点

注意删除一个点的时候,会使连通分量数减少

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long LL;
const int maxn = 5005;
const int inf = 0x3f3f3f3f;
struct node{
	int v;
	int next;
}e[maxn*2];
int head[maxn];
int tot;


int n,m;
int idel;

int low[maxn];
int dfn[maxn];
int cut[maxn];
bool instack[maxn];
int id;

template void checkmax(T &a,T b){
	if(b > a)a = b;
}

void add(int u,int v){
	e[tot].v = v;
	e[tot].next = head[u];
	head[u] = tot ++;
}

void init(){
	memset(head,-1,sizeof(head));
	tot = 0;
}

void Tarjan(int u,int pre){
	dfn[u] = low[u] = id ++;
	instack[u] = true;
	int child = 0;
	for(int i=head[u];i!=-1;i=e[i].next){
		int v = e[i].v;
		if(v == pre)continue;
		if(v == idel)continue;
		if(dfn[v] == -1																	){
			child ++;
			Tarjan(v,u);
			low[u] = min(low[u],low[v]);
			if(pre != -1 && low[v] >= dfn[u]){
				cut[u] ++; 
			}
		}
		else if(instack[v] == true){
			low[u] = min(low[u],dfn[v]);
		}
	}
	if(pre == -1){
		cut[u] = child - 1;
	}
	instack[u] = false;
}

int gao(){
	memset(instack,false,sizeof(instack));
	memset(dfn,-1,sizeof(dfn));
	memset(cut,0,sizeof(cut));

	id = 0;
	int cnt = 0;
	int ans = 0;
	for(int i=0;i



你可能感兴趣的:(hdu)