Educational Codeforces Round 33 (Rated for Div. 2)C.Rumor并查集
题意:首先用并查集把N个人分成几块,然后每个块当中选取一个最小权值 加到答案中
/**
* Author1: low-equipped w_udixixi
* Author2: Sher丶lock
* Date :2019-08-13
**/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<queue>
#include<map>
#define ll long long
#define pb push_back
#define rep(x,a,b) for (ll x=a;x<=b;x++)
#define repp(x,a,b) for (ll x=a;x<b;x++)
#define pi 3.14159265358979323846
#define mem(a,x) memset(a,x,sizeof a)
using namespace std;
const int maxn=2e5+7;
const ll INF=1e9;
const ll INFF=1e18;
ll fa[maxn];
ll w[maxn];
ll a[maxn];
ll find(ll x)
{
if (fa[x]!=x)
return fa[x]=find(fa[x]);
return fa[x];
}
int main()
{
ll n,m,x,y;
ll ans=0;
scanf("%lld%lld",&n,&m);
rep(i,1,n)scanf("%lld",&a[i]);
rep(i,1,n)fa[i]=i;
rep(i,1,m)
{
scanf("%lld%lld",&x,&y);
x=find(x);
y=find(y);
fa[x]=y;
a[y]=min(a[x],a[y]);
}
rep(i,1,n)
{
if (i==find(i))
ans+=a[i];
}
cout<<ans<<endl;
}