• 【BZOJ3714】Kuglarz


    题面

    http://darkbzoj.tk/problem/3714

    题解

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #define ri register int
    #define N 2050
    using namespace std;
    struct edge{
      int u,v,l;
      bool operator < (const edge& rhs) const {
        return l<rhs.l;
      }
    } e[N*N];
    int f[N];
    int n;
    int findroot(int x){
      if (f[x]==x) return x;
      return f[x]=findroot(f[x]);
    }
    int main(){
      int x,cc=0;
      scanf("%d",&n);
      for (ri i=1;i<=n;i++) 
        for (ri j=i;j<=n;j++) {
          scanf("%d",&x);
          e[++cc]=(edge){i,j+1,x};
        }
      sort(e+1,e+cc+1);
      int tot=n+1;
      for (ri i=1;i<=n+1;i++) f[i]=i;
      long long ans=0;
      for (ri i=1;i<=cc;i++) {
        int u=findroot(e[i].u),v=findroot(e[i].v);
        if (u!=v) {
          ans+=e[i].l;
          f[u]=v;
          tot--;
          if (tot==1) {
            printf("%lld
    ",ans);
            return 0;
          }
        }
      }
      return 0;
    }
  • 相关阅读:
    浏览器渲染页面
    递归求1-100之和
    border属性
    ES6 Class
    数组去重
    get、post请求
    对象冒充继承
    原型链继承
    实现JS数据拷贝
    【转】centos升级curl版本
  • 原文地址:https://www.cnblogs.com/shxnb666/p/11275439.html
Copyright © 2020-2023  润新知