• Bio

    #include<bits/stdc++.h> using namespace std; #define ll long long struct s{ ll u,v,w; }; bool cmp(ll a,ll b){ return a.w<b.w; } ll fa[5050]; ll find(ll x){ if(fa[x]==x)return x; return fa[x]=find(fa[x]); }

    int main(){

    ll n,m;
    cin>>n>>m;
    vector<s> e(m);
    for(ll i=1;i<=m;i++){
    	cin>>e[i].u>>e[i].v>>e[i].w;
    }
    sort(e.begin(),e.end(),cmp);
    for(ll i=1;i<=n;i++){
    	fa[i]=i;
    }
    ll t=0;
    ll cnt=0;
    for(ll i=1;i<=m;i++){
    	ll ru=find(e[i].u);
    	ll rv=find(e[i].v);
    	if(ru!=rv){
    		fa[ru]=rv;
    		t+=w[i].w;
    		cnt++;
    	}
    	if(cnt==n-1)break;
    }
    if(cnt==n-1)cout<<t;
    else cout<<"orz";
    
    return 0;
    

    }

  • Accepted Problems

  • Recent Activities

    This person is lazy and didn't join any contests or homework.
  • Recent Solutions

    This person is lazy and didn't write any solutions.

Problem Tags

基础语法
3
C++课程
3
P2
3
一重循环
2
p2-6
2
基础算法
1
递归
1
基础
1
一维数组
1
语法
1
数组
1