Submission #872144

# Submission time Handle Problem Language Result Execution time Memory
872144 2023-11-12T11:33:20 Z SalihSahin Euklid (COCI20_euklid) C++14
0 / 110
3 ms 9816 KB
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long 
using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9+7;
const int inf = 1e18 + 10;

vector<int> adj[N];
int par[N], mx[N];

int find(int a){
    if(a == par[a]) return a;
    return par[a] = find(par[a]);
} 

void merge(int a, int b){
    a = find(a), b = find(b);

    par[b] = a;
    mx[a] = max(mx[a], mx[b]);
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<pair<int, int> > val(n);
    for(int i = 0; i < n; i++){
        cin>>val[i].first;
        val[i].second = i+1;
        mx[i+1] = val[i].first;
        par[i+1] = i+1;
    }
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    sort(val.begin(), val.end());
    vector<int> vis(N);
    int ans = 0;

    for(auto itr: val){
        int node = itr.second;
        for(auto v: adj[node]){
            if(vis[v] && find(v) != find(node)){
                ans += (mx[find(node)] + mx[find(v)]);
                merge(v, node);
            }
        }
        vis[node] = 1;
    }

    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9564 KB Integer parameter [name=a] equals to 0, violates the range [1, 10^18]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9564 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9816 KB Integer parameter [name=a] equals to 0, violates the range [1, 10^18]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9564 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 9564 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9564 KB Integer parameter [name=a] equals to 0, violates the range [1, 10^18]
2 Halted 0 ms 0 KB -