Submission #374352

# Submission time Handle Problem Language Result Execution time Memory
374352 2021-03-07T08:09:06 Z VEGAnn Sjekira (COCI20_sjekira) C++14
0 / 110
39 ms 3684 KB
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define i3 array<int,3>
#define pi3 pair<pair<int, int>, int>
#define ft first
#define sd second
using namespace std;
typedef long double ld;
typedef long long ll;
const ld E = 1e-9;
const int N = 100100;
vector<pi3> edgs;
int n, pre[N];
ll t[N], mx[N], ans = 0;

int get(int x) { return (pre[x] == x ? x : pre[x] = get(pre[x])); }

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> t[i];
        pre[i] = i;
        mx[i] = t[i];
    }

    for (int i = 1; i < n; i++){
        int x, y; cin >> x >> y; x--; y--;

//        edgs.PB({t[x] + t[y], x, y});
        edgs.PB(MP(MP(t[x] + t[y], x), y));
    }

    sort(all(edgs));

    for (pi3 cr : edgs){
//        int x = cr[1], y = cr[2];
        int x = cr.ft.sd, y = cr.sd;

        x = get(x);
        y = get(y);

        ans += mx[x];
        ans += mx[y];

        mx[x] = max(mx[x], mx[y]);
        pre[y] = x;
    }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 3684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -