#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib>
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define int long long
#define double long double
const int mxn=2e5,inf=1e18,minf=-1e18;
int val[mxn+10],ans=0;
vector<int>adj[mxn+10];
int mark[mxn+10];
int32_t main(){
int n,m,q;cin>>n>>m>>q;
if(q)return 0;
for(int i=1;i<=n;i++)cin>>val[i];
for(int i=0;i<n-1;i++){
int a,b;cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
pair<pii,int> st={{minf,0},-1};
for(int i=1;i<=n;i++)st=max(st,{{val[i],-adj[i].size()},i});
int ans=0;
priority_queue<pair<pii,int>,vector<pair<pii,int>>,greater<pair<pii,int>>>pq;
pq.push({{0,0},st.s});
while(!pq.empty()){
int cur=pq.top().s,cost=pq.top().f.f;
pq.pop();
if(mark[cur])continue;
mark[cur]=1;
ans+=cost;
for(auto i:adj[cur])pq.push({{val[cur],val[i]},i});
}
cout<<ans;
return 0;
}
/*
non tree
we still need to take the max
we still need to have everything connected
we can find mst? cost->val of node????
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
182 ms |
24548 KB |
Output is correct |
3 |
Correct |
177 ms |
24256 KB |
Output is correct |
4 |
Correct |
178 ms |
18492 KB |
Output is correct |
5 |
Correct |
131 ms |
17004 KB |
Output is correct |
6 |
Correct |
167 ms |
18372 KB |
Output is correct |
7 |
Correct |
185 ms |
18560 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
182 ms |
24548 KB |
Output is correct |
3 |
Correct |
177 ms |
24256 KB |
Output is correct |
4 |
Correct |
178 ms |
18492 KB |
Output is correct |
5 |
Correct |
131 ms |
17004 KB |
Output is correct |
6 |
Correct |
167 ms |
18372 KB |
Output is correct |
7 |
Correct |
185 ms |
18560 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
178 ms |
18336 KB |
Output is correct |
11 |
Correct |
215 ms |
25792 KB |
Output is correct |
12 |
Correct |
197 ms |
24904 KB |
Output is correct |
13 |
Correct |
207 ms |
25676 KB |
Output is correct |
14 |
Correct |
168 ms |
18300 KB |
Output is correct |
15 |
Correct |
172 ms |
18516 KB |
Output is correct |
16 |
Correct |
164 ms |
18260 KB |
Output is correct |
17 |
Correct |
165 ms |
18300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
182 ms |
24548 KB |
Output is correct |
3 |
Correct |
177 ms |
24256 KB |
Output is correct |
4 |
Correct |
178 ms |
18492 KB |
Output is correct |
5 |
Correct |
131 ms |
17004 KB |
Output is correct |
6 |
Correct |
167 ms |
18372 KB |
Output is correct |
7 |
Correct |
185 ms |
18560 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
178 ms |
18336 KB |
Output is correct |
11 |
Correct |
215 ms |
25792 KB |
Output is correct |
12 |
Correct |
197 ms |
24904 KB |
Output is correct |
13 |
Correct |
207 ms |
25676 KB |
Output is correct |
14 |
Correct |
168 ms |
18300 KB |
Output is correct |
15 |
Correct |
172 ms |
18516 KB |
Output is correct |
16 |
Correct |
164 ms |
18260 KB |
Output is correct |
17 |
Correct |
165 ms |
18300 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
250 ms |
19600 KB |
Output is correct |
20 |
Correct |
213 ms |
19260 KB |
Output is correct |
21 |
Correct |
233 ms |
19448 KB |
Output is correct |
22 |
Correct |
229 ms |
20164 KB |
Output is correct |
23 |
Correct |
246 ms |
20504 KB |
Output is correct |
24 |
Correct |
243 ms |
23496 KB |
Output is correct |
25 |
Correct |
274 ms |
28208 KB |
Output is correct |
26 |
Correct |
241 ms |
27340 KB |
Output is correct |
27 |
Correct |
253 ms |
28684 KB |
Output is correct |
28 |
Correct |
212 ms |
19332 KB |
Output is correct |
29 |
Correct |
214 ms |
20668 KB |
Output is correct |
30 |
Correct |
259 ms |
23576 KB |
Output is correct |
31 |
Correct |
251 ms |
29404 KB |
Output is correct |
32 |
Correct |
279 ms |
27968 KB |
Output is correct |
33 |
Correct |
198 ms |
20016 KB |
Output is correct |
34 |
Correct |
261 ms |
26680 KB |
Output is correct |
35 |
Correct |
321 ms |
26748 KB |
Output is correct |
36 |
Correct |
262 ms |
27076 KB |
Output is correct |
37 |
Correct |
283 ms |
27436 KB |
Output is correct |
38 |
Correct |
248 ms |
21828 KB |
Output is correct |
39 |
Correct |
251 ms |
23492 KB |
Output is correct |
40 |
Correct |
236 ms |
22736 KB |
Output is correct |
41 |
Correct |
236 ms |
24564 KB |
Output is correct |
42 |
Correct |
283 ms |
24084 KB |
Output is correct |
43 |
Correct |
267 ms |
20056 KB |
Output is correct |
44 |
Correct |
283 ms |
20336 KB |
Output is correct |
45 |
Correct |
298 ms |
19984 KB |
Output is correct |
46 |
Correct |
292 ms |
20452 KB |
Output is correct |
47 |
Correct |
280 ms |
19928 KB |
Output is correct |
48 |
Correct |
276 ms |
19988 KB |
Output is correct |
49 |
Correct |
263 ms |
21452 KB |
Output is correct |
50 |
Correct |
239 ms |
19536 KB |
Output is correct |
51 |
Correct |
240 ms |
19796 KB |
Output is correct |
52 |
Correct |
221 ms |
18640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
182 ms |
24548 KB |
Output is correct |
3 |
Correct |
177 ms |
24256 KB |
Output is correct |
4 |
Correct |
178 ms |
18492 KB |
Output is correct |
5 |
Correct |
131 ms |
17004 KB |
Output is correct |
6 |
Correct |
167 ms |
18372 KB |
Output is correct |
7 |
Correct |
185 ms |
18560 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
178 ms |
18336 KB |
Output is correct |
11 |
Correct |
215 ms |
25792 KB |
Output is correct |
12 |
Correct |
197 ms |
24904 KB |
Output is correct |
13 |
Correct |
207 ms |
25676 KB |
Output is correct |
14 |
Correct |
168 ms |
18300 KB |
Output is correct |
15 |
Correct |
172 ms |
18516 KB |
Output is correct |
16 |
Correct |
164 ms |
18260 KB |
Output is correct |
17 |
Correct |
165 ms |
18300 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
250 ms |
19600 KB |
Output is correct |
20 |
Correct |
213 ms |
19260 KB |
Output is correct |
21 |
Correct |
233 ms |
19448 KB |
Output is correct |
22 |
Correct |
229 ms |
20164 KB |
Output is correct |
23 |
Correct |
246 ms |
20504 KB |
Output is correct |
24 |
Correct |
243 ms |
23496 KB |
Output is correct |
25 |
Correct |
274 ms |
28208 KB |
Output is correct |
26 |
Correct |
241 ms |
27340 KB |
Output is correct |
27 |
Correct |
253 ms |
28684 KB |
Output is correct |
28 |
Correct |
212 ms |
19332 KB |
Output is correct |
29 |
Correct |
214 ms |
20668 KB |
Output is correct |
30 |
Correct |
259 ms |
23576 KB |
Output is correct |
31 |
Correct |
251 ms |
29404 KB |
Output is correct |
32 |
Correct |
279 ms |
27968 KB |
Output is correct |
33 |
Correct |
198 ms |
20016 KB |
Output is correct |
34 |
Correct |
261 ms |
26680 KB |
Output is correct |
35 |
Correct |
321 ms |
26748 KB |
Output is correct |
36 |
Correct |
262 ms |
27076 KB |
Output is correct |
37 |
Correct |
283 ms |
27436 KB |
Output is correct |
38 |
Correct |
248 ms |
21828 KB |
Output is correct |
39 |
Correct |
251 ms |
23492 KB |
Output is correct |
40 |
Correct |
236 ms |
22736 KB |
Output is correct |
41 |
Correct |
236 ms |
24564 KB |
Output is correct |
42 |
Correct |
283 ms |
24084 KB |
Output is correct |
43 |
Correct |
267 ms |
20056 KB |
Output is correct |
44 |
Correct |
283 ms |
20336 KB |
Output is correct |
45 |
Correct |
298 ms |
19984 KB |
Output is correct |
46 |
Correct |
292 ms |
20452 KB |
Output is correct |
47 |
Correct |
280 ms |
19928 KB |
Output is correct |
48 |
Correct |
276 ms |
19988 KB |
Output is correct |
49 |
Correct |
263 ms |
21452 KB |
Output is correct |
50 |
Correct |
239 ms |
19536 KB |
Output is correct |
51 |
Correct |
240 ms |
19796 KB |
Output is correct |
52 |
Correct |
221 ms |
18640 KB |
Output is correct |
53 |
Correct |
1 ms |
6488 KB |
Output is correct |
54 |
Incorrect |
258 ms |
20476 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
182 ms |
24548 KB |
Output is correct |
3 |
Correct |
177 ms |
24256 KB |
Output is correct |
4 |
Correct |
178 ms |
18492 KB |
Output is correct |
5 |
Correct |
131 ms |
17004 KB |
Output is correct |
6 |
Correct |
167 ms |
18372 KB |
Output is correct |
7 |
Correct |
185 ms |
18560 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
178 ms |
18336 KB |
Output is correct |
11 |
Correct |
215 ms |
25792 KB |
Output is correct |
12 |
Correct |
197 ms |
24904 KB |
Output is correct |
13 |
Correct |
207 ms |
25676 KB |
Output is correct |
14 |
Correct |
168 ms |
18300 KB |
Output is correct |
15 |
Correct |
172 ms |
18516 KB |
Output is correct |
16 |
Correct |
164 ms |
18260 KB |
Output is correct |
17 |
Correct |
165 ms |
18300 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
250 ms |
19600 KB |
Output is correct |
20 |
Correct |
213 ms |
19260 KB |
Output is correct |
21 |
Correct |
233 ms |
19448 KB |
Output is correct |
22 |
Correct |
229 ms |
20164 KB |
Output is correct |
23 |
Correct |
246 ms |
20504 KB |
Output is correct |
24 |
Correct |
243 ms |
23496 KB |
Output is correct |
25 |
Correct |
274 ms |
28208 KB |
Output is correct |
26 |
Correct |
241 ms |
27340 KB |
Output is correct |
27 |
Correct |
253 ms |
28684 KB |
Output is correct |
28 |
Correct |
212 ms |
19332 KB |
Output is correct |
29 |
Correct |
214 ms |
20668 KB |
Output is correct |
30 |
Correct |
259 ms |
23576 KB |
Output is correct |
31 |
Correct |
251 ms |
29404 KB |
Output is correct |
32 |
Correct |
279 ms |
27968 KB |
Output is correct |
33 |
Correct |
198 ms |
20016 KB |
Output is correct |
34 |
Correct |
261 ms |
26680 KB |
Output is correct |
35 |
Correct |
321 ms |
26748 KB |
Output is correct |
36 |
Correct |
262 ms |
27076 KB |
Output is correct |
37 |
Correct |
283 ms |
27436 KB |
Output is correct |
38 |
Correct |
248 ms |
21828 KB |
Output is correct |
39 |
Correct |
251 ms |
23492 KB |
Output is correct |
40 |
Correct |
236 ms |
22736 KB |
Output is correct |
41 |
Correct |
236 ms |
24564 KB |
Output is correct |
42 |
Correct |
283 ms |
24084 KB |
Output is correct |
43 |
Correct |
267 ms |
20056 KB |
Output is correct |
44 |
Correct |
283 ms |
20336 KB |
Output is correct |
45 |
Correct |
298 ms |
19984 KB |
Output is correct |
46 |
Correct |
292 ms |
20452 KB |
Output is correct |
47 |
Correct |
280 ms |
19928 KB |
Output is correct |
48 |
Correct |
276 ms |
19988 KB |
Output is correct |
49 |
Correct |
263 ms |
21452 KB |
Output is correct |
50 |
Correct |
239 ms |
19536 KB |
Output is correct |
51 |
Correct |
240 ms |
19796 KB |
Output is correct |
52 |
Correct |
221 ms |
18640 KB |
Output is correct |
53 |
Correct |
1 ms |
6488 KB |
Output is correct |
54 |
Incorrect |
258 ms |
20476 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |