• bzoj 1123


    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
     
    点的双联通,找到割点后统计答案即可
    注意最后答案要乘2(看样例能看出来)
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #define ll long long
    using namespace std;
    
    const int maxn = 100010 ;
    
    const int maxm = 500010 ;
    
    int n,m,head[maxn],size,low[maxn],dfn[maxn],tt[maxn],tim;
    
    ll ans[maxn];
    
    struct edge{
        int v,nex;
    }e[maxm<<1];
    
    void adde(int u,int v){
        e[size].v=v;e[size].nex=head[u];head[u]=size++;
    }
    
    void dfs(int u){
        low[u]=dfn[u]=++tim;
        int t=0;tt[u]=1;
        for(int i=head[u];~i;i=e[i].nex){
            int v=e[i].v;
            if(!dfn[v]){
                dfs(v);
                low[u]=min(low[u],low[v]);
                tt[u]+=tt[v];
                if(low[v]>=dfn[u]) {
                    ans[u]+=(long long) t*tt[v];
                    t+=tt[v];
                }
            }else low[u]=min(low[u],dfn[v]);
        }
        ans[u]+=(ll)t*(n-t-1);
    }
    
    int main(){
        scanf("%d%d",&n,&m);
        memset(head,-1,sizeof(head));
        for(int i=1;i<=m;i++){
            int u,v;
            scanf("%d%d",&u,&v);
            adde(u,v);adde(v,u);
        }
        for(int i=1;i<=n;i++) 
        if(!dfn[i]) dfs(i);
        for(int i=1;i<=n;i++) printf("%lld
    ",(ans[i]+n-1)*2);
        return 0;
    } 
    View Code
  • 相关阅读:
    DRF简易了解
    Restful API接口规范
    Python分页
    vue笔记(一)
    CNN实现手写数字识别
    深度学习框架Keras
    NLP自然语言处理
    深度学习框架Tensorflow
    维度的区分
    矩阵求导
  • 原文地址:https://www.cnblogs.com/plysc/p/11440357.html
Copyright © 2020-2023  润新知