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<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int c[N];
int ans=0;
signed main(){
int n;
cin>>n;
int mx=0;
for(int i=1;i<=n;i++){
cin>>c[i];
ans+=c[i];
mx=max(mx,c[i]);
}
ans-=mx;
for(int i=1;i<n;i++){
int a,b;
cin>>a>>b;
ans+=max(c[a],c[b]);
}
cout<<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... |