zoukankan      html  css  js  c++  java
  • #割点,Tarjan#洛谷 5058 [ZJOI2004]嗅探器

    题目

    询问能编号最小的割点删掉后使(a)(b)无法连通


    分析

    考虑将(a)当作根,那么割点的dfn小于等于(b)的dfn就可以了,
    怎么会呢,如果有一个环呢,所以得要让割点的子节点小于等于(b)的dfn才可以


    代码

    #include <cstdio>
    #include <cctype>
    #define rr register
    using namespace std;
    const int N=200011;
    struct node{int y,next;}e[500011];
    int as[N],dfn[N],low[N],cut[N],et=1,A,n,m,tot,root;
    inline signed iut(){
    	rr int ans=0; rr char c=getchar();
    	while (!isdigit(c)) c=getchar();
    	while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
    	return ans;
    }
    inline signed min(int a,int b){return a<b?a:b;}
    inline void tarjan(int x,int F){
    	dfn[x]=low[x]=++tot; rr int sub=0;
    	for (rr int i=as[x];i;i=e[i].next)
    	if (!dfn[e[i].y]){
    		tarjan(e[i].y,i^1);
    		low[x]=min(low[x],low[e[i].y]);
    		if (dfn[x]<=low[e[i].y]){
    			++sub;
    			if (x!=root||sub>1){
    				if (dfn[e[i].y]<=dfn[A]) cut[x]=1;
    			}
    		}
    	}else if (i!=F) low[x]=min(low[x],dfn[e[i].y]);
    }
    signed main(){
    	n=iut();
    	while (1){
    		rr int x=iut(),y=iut();
    		if (!x&&!y) break;
    		e[++et]=(node){y,as[x]},as[x]=et,
    		e[++et]=(node){x,as[y]},as[y]=et;
    	}
    	root=iut(),A=iut(),tarjan(root,0);
    	for (rr int i=1;i<=n;++i)
    	     if (cut[i]) return !printf("%d",i);
    	return !printf("No solution");
    }
    
  • 相关阅读:
    linux下源码安装python3
    FTP 命令
    Linux Shell数值比较和字符串比较及相关
    mount umount sort du tar
    linux 自动检查ssh脚本
    删除linux访问记录(message删不了)
    h3c 备份脚本
    linux 批量scp 脚本
    Linux 删除几天前的文件脚本
    博达交换机镜像检查,镜像丢失自动添加脚本
  • 原文地址:https://www.cnblogs.com/Spare-No-Effort/p/13922504.html
Copyright © 2011-2022 走看看