제출 #1242531

#제출 시각아이디문제언어결과실행 시간메모리
1242531hainam2k9Sjekira (COCI20_sjekira)C++20
110 / 110
24 ms3260 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
struct DSU{
    int p[MAXN],sz[MAXN],MAX[MAXN];
    void init(int n, int a[]){
        for(int i = 1; i<=n; ++i)
            p[i]=i, sz[i]=1, MAX[i]=a[i];
    }
    int Find(int u){
        if(u==p[u]) return u;
        return p[u]=Find(p[u]);
    }
    void Union(int x, int y){
        if(sz[x]<sz[y]) swap(x,y);
        p[y]=x, sz[x]+=sz[y], MAX[x]=max(MAX[x],MAX[y]);
    }
}dsu;
int n,a[MAXN];
ll rs=0;
vector<pair<int,pair<int,int>>> v;
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n;
    for(int i = 1; i<=n; ++i)
        cin >> a[i];
    for(int i = 1; i<n; ++i){
        int x,y;
        cin >> x >> y;
        v.pb(max(a[x],a[y]),mp(x,y));
    }
    sort(v.begin(),v.end());
    dsu.init(n,a);
    for(int i = 0; i<sz(v); ++i){
        pair<int,int> p=v[i].se;
        p.fi=dsu.Find(p.fi), p.se=dsu.Find(p.se);
        if(p.fi!=p.se) rs+=dsu.MAX[p.fi]+dsu.MAX[p.se], dsu.Union(p.fi,p.se);
    }
    cout << rs;
}

컴파일 시 표준 에러 (stderr) 메시지

sjekira.cpp: In function 'int main()':
sjekira.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sjekira.cpp:43:45: note: in expansion of macro 'fo'
   43 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
sjekira.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sjekira.cpp:43:45: note: in expansion of macro 'fo'
   43 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...