#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];
vector<int>adj[mxn+10];
int mark[mxn+10],dist[mxn+10],p[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],dist[i]=inf;
for(int i=0;i<m;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;
//greedy cost, if cost equal then we take the node with the least val first(wanna keep the large val as leaf)
pq.push({{0,0},st.s});
dist[st.s]=0;
while(!pq.empty()){
int cur=pq.top().s,cost=pq.top().f.f;
pq.pop();
if(dist[cur]<cost)continue;
for(auto i:adj[cur])if(i!=p[cur]&&val[cur]<dist[i]){
dist[i]=val[cur];
p[i]=cur;
pq.push({{val[cur],val[i]},i});
}
}
for(int i=1;i<=n;i++)ans+=dist[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????
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
122 ms |
19180 KB |
Output is correct |
3 |
Correct |
132 ms |
19332 KB |
Output is correct |
4 |
Correct |
121 ms |
19232 KB |
Output is correct |
5 |
Correct |
121 ms |
19288 KB |
Output is correct |
6 |
Correct |
120 ms |
19284 KB |
Output is correct |
7 |
Correct |
122 ms |
19328 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
122 ms |
19180 KB |
Output is correct |
3 |
Correct |
132 ms |
19332 KB |
Output is correct |
4 |
Correct |
121 ms |
19232 KB |
Output is correct |
5 |
Correct |
121 ms |
19288 KB |
Output is correct |
6 |
Correct |
120 ms |
19284 KB |
Output is correct |
7 |
Correct |
122 ms |
19328 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
154 ms |
20024 KB |
Output is correct |
11 |
Correct |
164 ms |
20128 KB |
Output is correct |
12 |
Correct |
151 ms |
20048 KB |
Output is correct |
13 |
Correct |
156 ms |
19988 KB |
Output is correct |
14 |
Correct |
159 ms |
20184 KB |
Output is correct |
15 |
Correct |
161 ms |
20188 KB |
Output is correct |
16 |
Correct |
170 ms |
20052 KB |
Output is correct |
17 |
Correct |
188 ms |
20020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
122 ms |
19180 KB |
Output is correct |
3 |
Correct |
132 ms |
19332 KB |
Output is correct |
4 |
Correct |
121 ms |
19232 KB |
Output is correct |
5 |
Correct |
121 ms |
19288 KB |
Output is correct |
6 |
Correct |
120 ms |
19284 KB |
Output is correct |
7 |
Correct |
122 ms |
19328 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
154 ms |
20024 KB |
Output is correct |
11 |
Correct |
164 ms |
20128 KB |
Output is correct |
12 |
Correct |
151 ms |
20048 KB |
Output is correct |
13 |
Correct |
156 ms |
19988 KB |
Output is correct |
14 |
Correct |
159 ms |
20184 KB |
Output is correct |
15 |
Correct |
161 ms |
20188 KB |
Output is correct |
16 |
Correct |
170 ms |
20052 KB |
Output is correct |
17 |
Correct |
188 ms |
20020 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
191 ms |
21072 KB |
Output is correct |
20 |
Correct |
194 ms |
20984 KB |
Output is correct |
21 |
Correct |
215 ms |
21304 KB |
Output is correct |
22 |
Correct |
230 ms |
21740 KB |
Output is correct |
23 |
Correct |
265 ms |
22216 KB |
Output is correct |
24 |
Correct |
208 ms |
23752 KB |
Output is correct |
25 |
Correct |
214 ms |
25140 KB |
Output is correct |
26 |
Correct |
260 ms |
28492 KB |
Output is correct |
27 |
Correct |
216 ms |
29368 KB |
Output is correct |
28 |
Correct |
205 ms |
21448 KB |
Output is correct |
29 |
Correct |
209 ms |
22716 KB |
Output is correct |
30 |
Correct |
219 ms |
25136 KB |
Output is correct |
31 |
Correct |
218 ms |
31408 KB |
Output is correct |
32 |
Correct |
221 ms |
26196 KB |
Output is correct |
33 |
Correct |
189 ms |
22020 KB |
Output is correct |
34 |
Correct |
216 ms |
24336 KB |
Output is correct |
35 |
Correct |
233 ms |
28688 KB |
Output is correct |
36 |
Correct |
213 ms |
28576 KB |
Output is correct |
37 |
Correct |
231 ms |
29500 KB |
Output is correct |
38 |
Correct |
212 ms |
23832 KB |
Output is correct |
39 |
Correct |
251 ms |
25284 KB |
Output is correct |
40 |
Correct |
227 ms |
22900 KB |
Output is correct |
41 |
Correct |
192 ms |
19536 KB |
Output is correct |
42 |
Correct |
187 ms |
19632 KB |
Output is correct |
43 |
Correct |
250 ms |
21804 KB |
Output is correct |
44 |
Correct |
221 ms |
21856 KB |
Output is correct |
45 |
Correct |
257 ms |
21936 KB |
Output is correct |
46 |
Correct |
216 ms |
21896 KB |
Output is correct |
47 |
Correct |
237 ms |
21780 KB |
Output is correct |
48 |
Correct |
212 ms |
21584 KB |
Output is correct |
49 |
Correct |
260 ms |
22252 KB |
Output is correct |
50 |
Correct |
203 ms |
21584 KB |
Output is correct |
51 |
Correct |
224 ms |
21664 KB |
Output is correct |
52 |
Correct |
208 ms |
21016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
122 ms |
19180 KB |
Output is correct |
3 |
Correct |
132 ms |
19332 KB |
Output is correct |
4 |
Correct |
121 ms |
19232 KB |
Output is correct |
5 |
Correct |
121 ms |
19288 KB |
Output is correct |
6 |
Correct |
120 ms |
19284 KB |
Output is correct |
7 |
Correct |
122 ms |
19328 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
154 ms |
20024 KB |
Output is correct |
11 |
Correct |
164 ms |
20128 KB |
Output is correct |
12 |
Correct |
151 ms |
20048 KB |
Output is correct |
13 |
Correct |
156 ms |
19988 KB |
Output is correct |
14 |
Correct |
159 ms |
20184 KB |
Output is correct |
15 |
Correct |
161 ms |
20188 KB |
Output is correct |
16 |
Correct |
170 ms |
20052 KB |
Output is correct |
17 |
Correct |
188 ms |
20020 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
191 ms |
21072 KB |
Output is correct |
20 |
Correct |
194 ms |
20984 KB |
Output is correct |
21 |
Correct |
215 ms |
21304 KB |
Output is correct |
22 |
Correct |
230 ms |
21740 KB |
Output is correct |
23 |
Correct |
265 ms |
22216 KB |
Output is correct |
24 |
Correct |
208 ms |
23752 KB |
Output is correct |
25 |
Correct |
214 ms |
25140 KB |
Output is correct |
26 |
Correct |
260 ms |
28492 KB |
Output is correct |
27 |
Correct |
216 ms |
29368 KB |
Output is correct |
28 |
Correct |
205 ms |
21448 KB |
Output is correct |
29 |
Correct |
209 ms |
22716 KB |
Output is correct |
30 |
Correct |
219 ms |
25136 KB |
Output is correct |
31 |
Correct |
218 ms |
31408 KB |
Output is correct |
32 |
Correct |
221 ms |
26196 KB |
Output is correct |
33 |
Correct |
189 ms |
22020 KB |
Output is correct |
34 |
Correct |
216 ms |
24336 KB |
Output is correct |
35 |
Correct |
233 ms |
28688 KB |
Output is correct |
36 |
Correct |
213 ms |
28576 KB |
Output is correct |
37 |
Correct |
231 ms |
29500 KB |
Output is correct |
38 |
Correct |
212 ms |
23832 KB |
Output is correct |
39 |
Correct |
251 ms |
25284 KB |
Output is correct |
40 |
Correct |
227 ms |
22900 KB |
Output is correct |
41 |
Correct |
192 ms |
19536 KB |
Output is correct |
42 |
Correct |
187 ms |
19632 KB |
Output is correct |
43 |
Correct |
250 ms |
21804 KB |
Output is correct |
44 |
Correct |
221 ms |
21856 KB |
Output is correct |
45 |
Correct |
257 ms |
21936 KB |
Output is correct |
46 |
Correct |
216 ms |
21896 KB |
Output is correct |
47 |
Correct |
237 ms |
21780 KB |
Output is correct |
48 |
Correct |
212 ms |
21584 KB |
Output is correct |
49 |
Correct |
260 ms |
22252 KB |
Output is correct |
50 |
Correct |
203 ms |
21584 KB |
Output is correct |
51 |
Correct |
224 ms |
21664 KB |
Output is correct |
52 |
Correct |
208 ms |
21016 KB |
Output is correct |
53 |
Correct |
2 ms |
8536 KB |
Output is correct |
54 |
Incorrect |
221 ms |
21536 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6744 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6744 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
122 ms |
19180 KB |
Output is correct |
3 |
Correct |
132 ms |
19332 KB |
Output is correct |
4 |
Correct |
121 ms |
19232 KB |
Output is correct |
5 |
Correct |
121 ms |
19288 KB |
Output is correct |
6 |
Correct |
120 ms |
19284 KB |
Output is correct |
7 |
Correct |
122 ms |
19328 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
154 ms |
20024 KB |
Output is correct |
11 |
Correct |
164 ms |
20128 KB |
Output is correct |
12 |
Correct |
151 ms |
20048 KB |
Output is correct |
13 |
Correct |
156 ms |
19988 KB |
Output is correct |
14 |
Correct |
159 ms |
20184 KB |
Output is correct |
15 |
Correct |
161 ms |
20188 KB |
Output is correct |
16 |
Correct |
170 ms |
20052 KB |
Output is correct |
17 |
Correct |
188 ms |
20020 KB |
Output is correct |
18 |
Correct |
2 ms |
8536 KB |
Output is correct |
19 |
Correct |
191 ms |
21072 KB |
Output is correct |
20 |
Correct |
194 ms |
20984 KB |
Output is correct |
21 |
Correct |
215 ms |
21304 KB |
Output is correct |
22 |
Correct |
230 ms |
21740 KB |
Output is correct |
23 |
Correct |
265 ms |
22216 KB |
Output is correct |
24 |
Correct |
208 ms |
23752 KB |
Output is correct |
25 |
Correct |
214 ms |
25140 KB |
Output is correct |
26 |
Correct |
260 ms |
28492 KB |
Output is correct |
27 |
Correct |
216 ms |
29368 KB |
Output is correct |
28 |
Correct |
205 ms |
21448 KB |
Output is correct |
29 |
Correct |
209 ms |
22716 KB |
Output is correct |
30 |
Correct |
219 ms |
25136 KB |
Output is correct |
31 |
Correct |
218 ms |
31408 KB |
Output is correct |
32 |
Correct |
221 ms |
26196 KB |
Output is correct |
33 |
Correct |
189 ms |
22020 KB |
Output is correct |
34 |
Correct |
216 ms |
24336 KB |
Output is correct |
35 |
Correct |
233 ms |
28688 KB |
Output is correct |
36 |
Correct |
213 ms |
28576 KB |
Output is correct |
37 |
Correct |
231 ms |
29500 KB |
Output is correct |
38 |
Correct |
212 ms |
23832 KB |
Output is correct |
39 |
Correct |
251 ms |
25284 KB |
Output is correct |
40 |
Correct |
227 ms |
22900 KB |
Output is correct |
41 |
Correct |
192 ms |
19536 KB |
Output is correct |
42 |
Correct |
187 ms |
19632 KB |
Output is correct |
43 |
Correct |
250 ms |
21804 KB |
Output is correct |
44 |
Correct |
221 ms |
21856 KB |
Output is correct |
45 |
Correct |
257 ms |
21936 KB |
Output is correct |
46 |
Correct |
216 ms |
21896 KB |
Output is correct |
47 |
Correct |
237 ms |
21780 KB |
Output is correct |
48 |
Correct |
212 ms |
21584 KB |
Output is correct |
49 |
Correct |
260 ms |
22252 KB |
Output is correct |
50 |
Correct |
203 ms |
21584 KB |
Output is correct |
51 |
Correct |
224 ms |
21664 KB |
Output is correct |
52 |
Correct |
208 ms |
21016 KB |
Output is correct |
53 |
Correct |
2 ms |
8536 KB |
Output is correct |
54 |
Incorrect |
221 ms |
21536 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |