#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll=long long;
vector<int> adj[200005];
int a[200005];
struct A{
int u,v;
A(int u=0,int v=0):u(u),v(v){}
bool operator<(const A &o)const{
if(a[u]!=a[o.u]) return a[u]>a[o.u];
return a[v]>a[o.u];
}
};
priority_queue<A> pq;
bitset<200005> vis;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int n,m,Q; cin>>n>>m>>Q;
int mx=1;
for(int i=1;i<=n;++i){
cin>>a[i];
if(a[i]>a[mx]) mx=i;
}
for(int i=0;i<m;++i){
int u,v; cin>>u>>v;
adj[u].eb(v), adj[v].eb(u);
}
ll ans=0;
vis[mx]=1;
for(auto &v:adj[mx]) pq.emplace(mx,v);
while(pq.size()){
auto [p,u]=pq.top(); pq.pop();
if(vis[u]) continue;
ans+=a[p];
vis[u]=1;
for(auto &v:adj[u]){
if(vis[v]) continue;
pq.emplace(u,v);
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
51 ms |
14928 KB |
Output is correct |
3 |
Correct |
51 ms |
14964 KB |
Output is correct |
4 |
Correct |
50 ms |
14932 KB |
Output is correct |
5 |
Correct |
50 ms |
15052 KB |
Output is correct |
6 |
Correct |
50 ms |
14932 KB |
Output is correct |
7 |
Correct |
50 ms |
14932 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
51 ms |
14928 KB |
Output is correct |
3 |
Correct |
51 ms |
14964 KB |
Output is correct |
4 |
Correct |
50 ms |
14932 KB |
Output is correct |
5 |
Correct |
50 ms |
15052 KB |
Output is correct |
6 |
Correct |
50 ms |
14932 KB |
Output is correct |
7 |
Correct |
50 ms |
14932 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
59 ms |
16544 KB |
Output is correct |
11 |
Correct |
59 ms |
16872 KB |
Output is correct |
12 |
Correct |
58 ms |
16468 KB |
Output is correct |
13 |
Correct |
63 ms |
16724 KB |
Output is correct |
14 |
Correct |
58 ms |
16420 KB |
Output is correct |
15 |
Correct |
61 ms |
16640 KB |
Output is correct |
16 |
Correct |
58 ms |
16504 KB |
Output is correct |
17 |
Correct |
58 ms |
16468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
51 ms |
14928 KB |
Output is correct |
3 |
Correct |
51 ms |
14964 KB |
Output is correct |
4 |
Correct |
50 ms |
14932 KB |
Output is correct |
5 |
Correct |
50 ms |
15052 KB |
Output is correct |
6 |
Correct |
50 ms |
14932 KB |
Output is correct |
7 |
Correct |
50 ms |
14932 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
59 ms |
16544 KB |
Output is correct |
11 |
Correct |
59 ms |
16872 KB |
Output is correct |
12 |
Correct |
58 ms |
16468 KB |
Output is correct |
13 |
Correct |
63 ms |
16724 KB |
Output is correct |
14 |
Correct |
58 ms |
16420 KB |
Output is correct |
15 |
Correct |
61 ms |
16640 KB |
Output is correct |
16 |
Correct |
58 ms |
16504 KB |
Output is correct |
17 |
Correct |
58 ms |
16468 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
144 ms |
16612 KB |
Output is correct |
20 |
Correct |
79 ms |
16464 KB |
Output is correct |
21 |
Correct |
78 ms |
16744 KB |
Output is correct |
22 |
Correct |
119 ms |
17036 KB |
Output is correct |
23 |
Correct |
123 ms |
17748 KB |
Output is correct |
24 |
Correct |
98 ms |
18144 KB |
Output is correct |
25 |
Correct |
98 ms |
18620 KB |
Output is correct |
26 |
Correct |
88 ms |
19392 KB |
Output is correct |
27 |
Correct |
99 ms |
19344 KB |
Output is correct |
28 |
Correct |
75 ms |
17084 KB |
Output is correct |
29 |
Correct |
95 ms |
17556 KB |
Output is correct |
30 |
Correct |
99 ms |
18372 KB |
Output is correct |
31 |
Correct |
81 ms |
19724 KB |
Output is correct |
32 |
Correct |
133 ms |
18408 KB |
Output is correct |
33 |
Correct |
87 ms |
15656 KB |
Output is correct |
34 |
Correct |
97 ms |
17868 KB |
Output is correct |
35 |
Correct |
105 ms |
19808 KB |
Output is correct |
36 |
Correct |
117 ms |
19984 KB |
Output is correct |
37 |
Correct |
88 ms |
19908 KB |
Output is correct |
38 |
Correct |
92 ms |
17268 KB |
Output is correct |
39 |
Correct |
103 ms |
17856 KB |
Output is correct |
40 |
Correct |
89 ms |
17560 KB |
Output is correct |
41 |
Correct |
72 ms |
15796 KB |
Output is correct |
42 |
Correct |
77 ms |
15956 KB |
Output is correct |
43 |
Correct |
89 ms |
16872 KB |
Output is correct |
44 |
Correct |
98 ms |
17104 KB |
Output is correct |
45 |
Correct |
113 ms |
17096 KB |
Output is correct |
46 |
Correct |
108 ms |
17044 KB |
Output is correct |
47 |
Correct |
110 ms |
16976 KB |
Output is correct |
48 |
Correct |
98 ms |
17016 KB |
Output is correct |
49 |
Correct |
116 ms |
17184 KB |
Output is correct |
50 |
Correct |
99 ms |
16764 KB |
Output is correct |
51 |
Correct |
93 ms |
17100 KB |
Output is correct |
52 |
Correct |
103 ms |
15184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
51 ms |
14928 KB |
Output is correct |
3 |
Correct |
51 ms |
14964 KB |
Output is correct |
4 |
Correct |
50 ms |
14932 KB |
Output is correct |
5 |
Correct |
50 ms |
15052 KB |
Output is correct |
6 |
Correct |
50 ms |
14932 KB |
Output is correct |
7 |
Correct |
50 ms |
14932 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
59 ms |
16544 KB |
Output is correct |
11 |
Correct |
59 ms |
16872 KB |
Output is correct |
12 |
Correct |
58 ms |
16468 KB |
Output is correct |
13 |
Correct |
63 ms |
16724 KB |
Output is correct |
14 |
Correct |
58 ms |
16420 KB |
Output is correct |
15 |
Correct |
61 ms |
16640 KB |
Output is correct |
16 |
Correct |
58 ms |
16504 KB |
Output is correct |
17 |
Correct |
58 ms |
16468 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
144 ms |
16612 KB |
Output is correct |
20 |
Correct |
79 ms |
16464 KB |
Output is correct |
21 |
Correct |
78 ms |
16744 KB |
Output is correct |
22 |
Correct |
119 ms |
17036 KB |
Output is correct |
23 |
Correct |
123 ms |
17748 KB |
Output is correct |
24 |
Correct |
98 ms |
18144 KB |
Output is correct |
25 |
Correct |
98 ms |
18620 KB |
Output is correct |
26 |
Correct |
88 ms |
19392 KB |
Output is correct |
27 |
Correct |
99 ms |
19344 KB |
Output is correct |
28 |
Correct |
75 ms |
17084 KB |
Output is correct |
29 |
Correct |
95 ms |
17556 KB |
Output is correct |
30 |
Correct |
99 ms |
18372 KB |
Output is correct |
31 |
Correct |
81 ms |
19724 KB |
Output is correct |
32 |
Correct |
133 ms |
18408 KB |
Output is correct |
33 |
Correct |
87 ms |
15656 KB |
Output is correct |
34 |
Correct |
97 ms |
17868 KB |
Output is correct |
35 |
Correct |
105 ms |
19808 KB |
Output is correct |
36 |
Correct |
117 ms |
19984 KB |
Output is correct |
37 |
Correct |
88 ms |
19908 KB |
Output is correct |
38 |
Correct |
92 ms |
17268 KB |
Output is correct |
39 |
Correct |
103 ms |
17856 KB |
Output is correct |
40 |
Correct |
89 ms |
17560 KB |
Output is correct |
41 |
Correct |
72 ms |
15796 KB |
Output is correct |
42 |
Correct |
77 ms |
15956 KB |
Output is correct |
43 |
Correct |
89 ms |
16872 KB |
Output is correct |
44 |
Correct |
98 ms |
17104 KB |
Output is correct |
45 |
Correct |
113 ms |
17096 KB |
Output is correct |
46 |
Correct |
108 ms |
17044 KB |
Output is correct |
47 |
Correct |
110 ms |
16976 KB |
Output is correct |
48 |
Correct |
98 ms |
17016 KB |
Output is correct |
49 |
Correct |
116 ms |
17184 KB |
Output is correct |
50 |
Correct |
99 ms |
16764 KB |
Output is correct |
51 |
Correct |
93 ms |
17100 KB |
Output is correct |
52 |
Correct |
103 ms |
15184 KB |
Output is correct |
53 |
Correct |
2 ms |
5724 KB |
Output is correct |
54 |
Incorrect |
106 ms |
16980 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5720 KB |
Output is correct |
2 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
51 ms |
14928 KB |
Output is correct |
3 |
Correct |
51 ms |
14964 KB |
Output is correct |
4 |
Correct |
50 ms |
14932 KB |
Output is correct |
5 |
Correct |
50 ms |
15052 KB |
Output is correct |
6 |
Correct |
50 ms |
14932 KB |
Output is correct |
7 |
Correct |
50 ms |
14932 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
59 ms |
16544 KB |
Output is correct |
11 |
Correct |
59 ms |
16872 KB |
Output is correct |
12 |
Correct |
58 ms |
16468 KB |
Output is correct |
13 |
Correct |
63 ms |
16724 KB |
Output is correct |
14 |
Correct |
58 ms |
16420 KB |
Output is correct |
15 |
Correct |
61 ms |
16640 KB |
Output is correct |
16 |
Correct |
58 ms |
16504 KB |
Output is correct |
17 |
Correct |
58 ms |
16468 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
144 ms |
16612 KB |
Output is correct |
20 |
Correct |
79 ms |
16464 KB |
Output is correct |
21 |
Correct |
78 ms |
16744 KB |
Output is correct |
22 |
Correct |
119 ms |
17036 KB |
Output is correct |
23 |
Correct |
123 ms |
17748 KB |
Output is correct |
24 |
Correct |
98 ms |
18144 KB |
Output is correct |
25 |
Correct |
98 ms |
18620 KB |
Output is correct |
26 |
Correct |
88 ms |
19392 KB |
Output is correct |
27 |
Correct |
99 ms |
19344 KB |
Output is correct |
28 |
Correct |
75 ms |
17084 KB |
Output is correct |
29 |
Correct |
95 ms |
17556 KB |
Output is correct |
30 |
Correct |
99 ms |
18372 KB |
Output is correct |
31 |
Correct |
81 ms |
19724 KB |
Output is correct |
32 |
Correct |
133 ms |
18408 KB |
Output is correct |
33 |
Correct |
87 ms |
15656 KB |
Output is correct |
34 |
Correct |
97 ms |
17868 KB |
Output is correct |
35 |
Correct |
105 ms |
19808 KB |
Output is correct |
36 |
Correct |
117 ms |
19984 KB |
Output is correct |
37 |
Correct |
88 ms |
19908 KB |
Output is correct |
38 |
Correct |
92 ms |
17268 KB |
Output is correct |
39 |
Correct |
103 ms |
17856 KB |
Output is correct |
40 |
Correct |
89 ms |
17560 KB |
Output is correct |
41 |
Correct |
72 ms |
15796 KB |
Output is correct |
42 |
Correct |
77 ms |
15956 KB |
Output is correct |
43 |
Correct |
89 ms |
16872 KB |
Output is correct |
44 |
Correct |
98 ms |
17104 KB |
Output is correct |
45 |
Correct |
113 ms |
17096 KB |
Output is correct |
46 |
Correct |
108 ms |
17044 KB |
Output is correct |
47 |
Correct |
110 ms |
16976 KB |
Output is correct |
48 |
Correct |
98 ms |
17016 KB |
Output is correct |
49 |
Correct |
116 ms |
17184 KB |
Output is correct |
50 |
Correct |
99 ms |
16764 KB |
Output is correct |
51 |
Correct |
93 ms |
17100 KB |
Output is correct |
52 |
Correct |
103 ms |
15184 KB |
Output is correct |
53 |
Correct |
2 ms |
5724 KB |
Output is correct |
54 |
Incorrect |
106 ms |
16980 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |