zoukankan      html  css  js  c++  java
  • BZOJ1123: [POI2008]BLO

    Description

    Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通。

    Input

    输入n<=100000 m<=500000及m条边

    Output

    输出n个数,代表如果把第i个点去掉,将有多少对点不能互通。

    Sample Input

    5 5
    1 2
    2 3
    1 3
    3 4
    4 5

    Sample Output

    8
    8
    16
    14
    8
     
    傻逼题我来挂个Tarjan跑割点的模板(话说BZOJ良心发现放开权限题了???)
    对于每个点,如果不是割点(割掉就不联通),那么答案显然是2*(n-1)
    如果是,那么割出来T个块,然后两两相乘累加即可
    //MT_LI
    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    struct node{
        int x,y,next;
    }a[2100000];int len,last[210000];
    void ins(int x,int y)
    {
        len++;
        a[len].x=x;a[len].y=y;
        a[len].next=last[x];last[x]=len;
    }
    int n,m;
    ll ans[210000];
    int tot[210000],cut[210000];
    int low[210000],dfn[210000],cnt;
    void dfs(int x)
    {
        tot[x]=1;dfn[x]=low[x]=++cnt;
        int sum=0,t=0;
        for(int k=last[x];k;k=a[k].next)
        {
            int y=a[k].y;
            if(!dfn[y])
            {
                dfs(y);
                tot[x]+=tot[y];
                low[x]=min(low[x],low[y]);
                if(low[y]>=dfn[x])
                {
                    t++;
                    ans[x]+=(ll)tot[y]*(n-tot[y]);
                    sum+=tot[y];
                    if(x!=1||t>1)cut[x]=1;
                }
            }
            else low[x]=min(low[x],dfn[y]);
        }
        if(cut[x])ans[x]+=(ll)(n-sum-1)*(sum+1)+(n-1);
        else ans[x]=2*(n-1);
    }
    int main()
    {
        scanf("%d%d",&n,&m);cnt=0;
        len=0;memset(last,0,sizeof(last));
        for(int i=1;i<=m;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            if(x!=y)ins(x,y),ins(y,x);
        }
        dfs(1);
        for(int i=1;i<=n;i++)printf("%lld
    ",ans[i]);
        return 0;
    }
    The deepest love I think,later than apart,I will live as you like
  • 相关阅读:
    JSP源码、改写Servlet为JSP、查看转译成为Servlet的文件、JSP字符编码设置
    使用Tomcat部署应用
    缓冲与缓存
    过滤器及请求封装器实现字符编码
    过滤器与请求封装器实现字符替换
    过滤器
    与请求相关的监听器
    区块链简介
    https协议简介
    http协议简介
  • 原文地址:https://www.cnblogs.com/MT-LI/p/9699439.html
Copyright © 2011-2022 走看看