This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "friend.h"
#include<iostream>
using namespace std;
const int N = 1e6 + 123;
int dsu[N];
int val[N];
int get(int x) {
if (x == dsu[x]) return x;
return dsu[x] = get(dsu[x]);
}
int findSample(int n,int confidence[],int host[],int protocol[]){
for (int i = 0 ; i < n ; ++ i) {
dsu[i] = i;
val[i] = confidence[i];
}
for (int i = 1 ; i < n ; ++ i) {
int j = host[i];
int x = get(i), y = get(j);
if (x == y) continue;
dsu[x] = y;
val[y] = max(val[y], val[x]);
}
int ans = 0;
for (int i = 0 ; i < n ; ++ i) {
int j = get(i);
ans += val[j];
val[j] = 0;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |