zoukankan      html  css  js  c++  java
  • bzoj1123(割点加路径统计)

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace  std;
    
    typedef long long ll;
    
    struct my{
      int next;
      int v;
    };
    
    const int maxn=100000+10;
    ll low[maxn],dfsn[maxn],size_[maxn],adj[maxn],fa,dfn,root,ans[maxn];
    my bian[maxn*10];
    bool cut[maxn];
    int m,n;
    
    void myinsert(int u,int v){
         bian[++fa].v=v;
         bian[fa].next=adj[u];
         adj[u]=fa;
    }
    
    void tarjan(ll x){
         dfsn[x]=low[x]=++dfn;
         ll ch=0,sum=0;
         size_[x]=1;
         for (int i=adj[x];i;i=bian[i].next){
            ll v=bian[i].v;
            if(!dfsn[v]){
                tarjan(v);
                size_[x]+=size_[v];
                low[x]=min(low[x],low[v]);
                if(dfsn[x]<=low[v]){
                    ch++;
                    ans[x]+=size_[v]*(n-size_[v]);
                    sum+=size_[v];
                    if(root!=x||ch>1){
                        cut[x]=1;
                    }
                }
            }
            else low[x]=min(low[x],dfsn[v]);
         }
         if(cut[x]) ans[x]+=(n-sum-1)*(sum+1)+(n-1);
         else ans[x]=2*(n-1);
    }
    
    int main(){
        int u,v;
        scanf("%d%d",&n,&m);
        for (int i=1;i<=m;i++){
            scanf("%d%d",&u,&v);
            myinsert(u,v);
            myinsert(v,u);
        }
        for (int i=1;i<=n;i++){
            if(!dfsn[i]){
                root=i;
                tarjan(i);
            }
        }
        for (int i=1;i<=n;i++){
           printf("%lld
    ",ans[i]);
        }
    return 0;
    }

  • 相关阅读:
    12迭代器
    11(2)Vector(向量)
    11(1) LinkList ---链表
    11集合(Collection<E>) Arraylist
    10异常
    乘法计算过程的模拟
    10 Date详解
    详细的OA系统学习
    8 math类
    Java开发中的23种设计模式详解
  • 原文地址:https://www.cnblogs.com/lmjer/p/8678317.html
Copyright © 2011-2022 走看看