답안 #706607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706607 2023-03-07T06:34:41 Z YugiHacker Sjeckanje (COCI21_sjeckanje) C++14
0 / 110
1 ms 468 KB
/*
	www.youtube.com/YugiHackerChannel
	oj.vnoi.info/user/YugiHackerKhongCopCode
*/
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn 100005
using namespace std;
int n, f[maxn];
long long ans;
int r[maxn];
#define pii pair<int,int>
#define fi first
#define se second
vector <pair<int, int> > a;
int get(int u)
{
    return r[u]==u?u:r[u]=get(r[u]);
}
void join(pii e)
{
    int u = e.fi, v = e.se;
    u = get(u), v = get(v);
    ans += f[u] + f[v];
    r[v] = u;
    f[u] = max(f[u], f[v]);
}
main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    f1 (i, n) cin >> f[i], r[i] = i;
    for (int i=1; i<n; i++)
    {
        int u, v;
        cin >> u >> v;
        a.push_back({u, v});
    }
    sort(a.begin(), a.end(), [](pii a, pii b){
            return max(f[a.fi], f[a.se]) < max(f[b.fi], f[b.se]);
         });
    for (auto p:a)
        join(p);
    cout << ans;
}

Compilation message

Main.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -