QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#518129 | #6322. Forestry | qqqaaazzz | RE | 2ms | 12020kb | C++14 | 877b | 2024-08-13 16:07:22 | 2024-08-13 16:07:22 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[200010];
vector<int> v[200010];
int x[200010],y[200010];
bool vis[200010];
int mi = 1e9;
int ans;
void dfs(int d){
vis[d] = true;
mi = min(mi,a[d]);
for (auto i : v[d]){
if(!vis[i]) dfs(i);
}
return;
}
void check(){
for (int i=1;i<=n;i++) vis[i] = false;
for (int i=1;i<=n;i++){
if(!vis[i]){
mi = 1e9;
dfs(i);
ans += mi;
}
}
return;
}
void che(int d){
if(d==n){
check();
return;
}
che(d+1);
vector<int> g1 = v[x[d]];
vector<int> g2 = v[y[d]];
v[x[d]].push_back(y[d]);
v[y[d]].push_back(x[d]);
che(d+1);
v[x[d]] = g1;
v[y[d]] = g2;
return;
}
signed main()
{
cin >> n;
for (int i=1;i<=n;i++) cin >> a[i];
for (int i=1;i<=n-1;i++){
cin >> x[i] >> y[i];
}
che(1);
cout << ans <<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10004kb
input:
4 1 2 3 4 1 2 2 4 3 2
output:
44
result:
ok 1 number(s): "44"
Test #2:
score: 0
Accepted
time: 2ms
memory: 12020kb
input:
5 3 5 6 5 1 4 1 2 3 3 5 1 3
output:
154
result:
ok 1 number(s): "154"
Test #3:
score: -100
Runtime Error
input:
278989 864394090 384799247 186936242 598547507 962916136 540758021 158527118 688236322 682301622 948660645 881768181 481432818 557201870 794956026 205262301 920739629 141926922 990361777 818811172 150579096 1032726 328924563 638044961 21740781 484574329 737977343 113738003 345289940 363021157 582495...