mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-17 12:06:47 +00:00
T203629 [$€₱2021 普及组] 赚钱
R61428370
This commit is contained in:
parent
f990dedacb
commit
05364a3261
34
Luogu/T203629/T203629.cpp
Normal file
34
Luogu/T203629/T203629.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int n, m, u[5000005], v[5000005], w[5000005], fa[5000005];
|
||||||
|
long long ans;
|
||||||
|
|
||||||
|
int find(int x) {
|
||||||
|
return fa[x] == x ? x : fa[x] = find(fa[x]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
scanf("%d%d", &n, &m);
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
scanf("%d%d", u + i, v + i);
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
scanf("%d", w + i);
|
||||||
|
fa[i] = i;
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
int fu = find(u[i]);
|
||||||
|
int fv = find(v[i]);
|
||||||
|
fa[fv] = fu;
|
||||||
|
w[fu] = max(w[fu], w[fv]);
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (fa[i] == i) {
|
||||||
|
ans += w[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("%lld\n", ans);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user