#include <bits/stdc++.h>
using namespace std;
#define int long long
struct UFDS{
vector<int> p,siz,mini;
UFDS(int n,vector<int> arr):p(n+1),siz(n+1,1),mini(n+1){
iota(p.begin(),p.end(),0);
mini=arr;
}
int findRoot(int x){
return p[x]==x ? x : p[x]=findRoot(p[x]);
}
int unite(int a,int b){
a = findRoot(a);
b = findRoot(b);
if(a==b)return -1;
if(siz[b]>siz[a])swap(a,b);
int ans = mini[a]+mini[b];
mini[a]=min(mini[a],mini[b]);
siz[a]+=siz[b];
p[b]=a;
return ans;
}
};
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m,q;
cin >> n >> m >> q;
vector<int> arr(n+1);
for(int i=1;i<=n;i++)cin>>arr[i];
vector<tuple<int,int,int>> edges;
for(int i=1;i<=m;i++){
int a,b;
cin >> a >> b;
edges.emplace_back(arr[a]+arr[b],a,b);
}
sort(edges.begin(),edges.end());
int baseans = (*max_element(arr.begin(),arr.end()));
for(int i=1;i<=n;i++){
baseans-=arr[i];
}
UFDS dsu(n,arr);
priority_queue<int> qu;
for(int i=0;i<m;i++){
auto [cost,a,b] = edges[i];
auto curr = dsu.unite(a,b);
if(curr==-1)continue;
baseans+=cost;
qu.emplace(cost-curr);
}
for(int i=0;i<=q;i++){
cout << baseans << '\n';
if(!qu.empty()){
baseans-=qu.top();
qu.pop();
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
41 ms |
15556 KB |
Output is correct |
3 |
Correct |
40 ms |
15552 KB |
Output is correct |
4 |
Correct |
54 ms |
15496 KB |
Output is correct |
5 |
Correct |
50 ms |
15540 KB |
Output is correct |
6 |
Correct |
49 ms |
15544 KB |
Output is correct |
7 |
Correct |
50 ms |
15540 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
41 ms |
15556 KB |
Output is correct |
3 |
Correct |
40 ms |
15552 KB |
Output is correct |
4 |
Correct |
54 ms |
15496 KB |
Output is correct |
5 |
Correct |
50 ms |
15540 KB |
Output is correct |
6 |
Correct |
49 ms |
15544 KB |
Output is correct |
7 |
Correct |
50 ms |
15540 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
62 ms |
15352 KB |
Output is correct |
11 |
Correct |
48 ms |
15552 KB |
Output is correct |
12 |
Correct |
47 ms |
15540 KB |
Output is correct |
13 |
Correct |
48 ms |
15444 KB |
Output is correct |
14 |
Correct |
65 ms |
15548 KB |
Output is correct |
15 |
Correct |
61 ms |
15540 KB |
Output is correct |
16 |
Correct |
60 ms |
15552 KB |
Output is correct |
17 |
Correct |
62 ms |
15544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
41 ms |
15556 KB |
Output is correct |
3 |
Correct |
40 ms |
15552 KB |
Output is correct |
4 |
Correct |
54 ms |
15496 KB |
Output is correct |
5 |
Correct |
50 ms |
15540 KB |
Output is correct |
6 |
Correct |
49 ms |
15544 KB |
Output is correct |
7 |
Correct |
50 ms |
15540 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
62 ms |
15352 KB |
Output is correct |
11 |
Correct |
48 ms |
15552 KB |
Output is correct |
12 |
Correct |
47 ms |
15540 KB |
Output is correct |
13 |
Correct |
48 ms |
15444 KB |
Output is correct |
14 |
Correct |
65 ms |
15548 KB |
Output is correct |
15 |
Correct |
61 ms |
15540 KB |
Output is correct |
16 |
Correct |
60 ms |
15552 KB |
Output is correct |
17 |
Correct |
62 ms |
15544 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
64 ms |
15544 KB |
Output is correct |
20 |
Correct |
66 ms |
15540 KB |
Output is correct |
21 |
Correct |
64 ms |
15540 KB |
Output is correct |
22 |
Correct |
64 ms |
15540 KB |
Output is correct |
23 |
Correct |
63 ms |
15548 KB |
Output is correct |
24 |
Correct |
70 ms |
15552 KB |
Output is correct |
25 |
Correct |
64 ms |
15540 KB |
Output is correct |
26 |
Correct |
60 ms |
15572 KB |
Output is correct |
27 |
Correct |
58 ms |
15540 KB |
Output is correct |
28 |
Correct |
61 ms |
15544 KB |
Output is correct |
29 |
Correct |
63 ms |
15436 KB |
Output is correct |
30 |
Correct |
61 ms |
15384 KB |
Output is correct |
31 |
Correct |
74 ms |
15388 KB |
Output is correct |
32 |
Correct |
65 ms |
15516 KB |
Output is correct |
33 |
Correct |
62 ms |
15496 KB |
Output is correct |
34 |
Correct |
64 ms |
15552 KB |
Output is correct |
35 |
Correct |
63 ms |
15548 KB |
Output is correct |
36 |
Correct |
62 ms |
15548 KB |
Output is correct |
37 |
Correct |
61 ms |
15548 KB |
Output is correct |
38 |
Correct |
61 ms |
15540 KB |
Output is correct |
39 |
Correct |
64 ms |
15560 KB |
Output is correct |
40 |
Correct |
66 ms |
15540 KB |
Output is correct |
41 |
Correct |
68 ms |
15544 KB |
Output is correct |
42 |
Correct |
63 ms |
15544 KB |
Output is correct |
43 |
Correct |
67 ms |
15436 KB |
Output is correct |
44 |
Correct |
66 ms |
15572 KB |
Output is correct |
45 |
Correct |
67 ms |
15544 KB |
Output is correct |
46 |
Correct |
68 ms |
15548 KB |
Output is correct |
47 |
Correct |
67 ms |
15552 KB |
Output is correct |
48 |
Correct |
68 ms |
15544 KB |
Output is correct |
49 |
Correct |
65 ms |
15548 KB |
Output is correct |
50 |
Correct |
66 ms |
15544 KB |
Output is correct |
51 |
Correct |
87 ms |
15540 KB |
Output is correct |
52 |
Correct |
57 ms |
15792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
41 ms |
15556 KB |
Output is correct |
3 |
Correct |
40 ms |
15552 KB |
Output is correct |
4 |
Correct |
54 ms |
15496 KB |
Output is correct |
5 |
Correct |
50 ms |
15540 KB |
Output is correct |
6 |
Correct |
49 ms |
15544 KB |
Output is correct |
7 |
Correct |
50 ms |
15540 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
62 ms |
15352 KB |
Output is correct |
11 |
Correct |
48 ms |
15552 KB |
Output is correct |
12 |
Correct |
47 ms |
15540 KB |
Output is correct |
13 |
Correct |
48 ms |
15444 KB |
Output is correct |
14 |
Correct |
65 ms |
15548 KB |
Output is correct |
15 |
Correct |
61 ms |
15540 KB |
Output is correct |
16 |
Correct |
60 ms |
15552 KB |
Output is correct |
17 |
Correct |
62 ms |
15544 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
64 ms |
15544 KB |
Output is correct |
20 |
Correct |
66 ms |
15540 KB |
Output is correct |
21 |
Correct |
64 ms |
15540 KB |
Output is correct |
22 |
Correct |
64 ms |
15540 KB |
Output is correct |
23 |
Correct |
63 ms |
15548 KB |
Output is correct |
24 |
Correct |
70 ms |
15552 KB |
Output is correct |
25 |
Correct |
64 ms |
15540 KB |
Output is correct |
26 |
Correct |
60 ms |
15572 KB |
Output is correct |
27 |
Correct |
58 ms |
15540 KB |
Output is correct |
28 |
Correct |
61 ms |
15544 KB |
Output is correct |
29 |
Correct |
63 ms |
15436 KB |
Output is correct |
30 |
Correct |
61 ms |
15384 KB |
Output is correct |
31 |
Correct |
74 ms |
15388 KB |
Output is correct |
32 |
Correct |
65 ms |
15516 KB |
Output is correct |
33 |
Correct |
62 ms |
15496 KB |
Output is correct |
34 |
Correct |
64 ms |
15552 KB |
Output is correct |
35 |
Correct |
63 ms |
15548 KB |
Output is correct |
36 |
Correct |
62 ms |
15548 KB |
Output is correct |
37 |
Correct |
61 ms |
15548 KB |
Output is correct |
38 |
Correct |
61 ms |
15540 KB |
Output is correct |
39 |
Correct |
64 ms |
15560 KB |
Output is correct |
40 |
Correct |
66 ms |
15540 KB |
Output is correct |
41 |
Correct |
68 ms |
15544 KB |
Output is correct |
42 |
Correct |
63 ms |
15544 KB |
Output is correct |
43 |
Correct |
67 ms |
15436 KB |
Output is correct |
44 |
Correct |
66 ms |
15572 KB |
Output is correct |
45 |
Correct |
67 ms |
15544 KB |
Output is correct |
46 |
Correct |
68 ms |
15548 KB |
Output is correct |
47 |
Correct |
67 ms |
15552 KB |
Output is correct |
48 |
Correct |
68 ms |
15544 KB |
Output is correct |
49 |
Correct |
65 ms |
15548 KB |
Output is correct |
50 |
Correct |
66 ms |
15544 KB |
Output is correct |
51 |
Correct |
87 ms |
15540 KB |
Output is correct |
52 |
Correct |
57 ms |
15792 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
67 ms |
15808 KB |
Output is correct |
55 |
Correct |
66 ms |
15796 KB |
Output is correct |
56 |
Correct |
100 ms |
16808 KB |
Output is correct |
57 |
Correct |
107 ms |
20156 KB |
Output is correct |
58 |
Correct |
103 ms |
20160 KB |
Output is correct |
59 |
Correct |
103 ms |
20188 KB |
Output is correct |
60 |
Correct |
77 ms |
17828 KB |
Output is correct |
61 |
Correct |
101 ms |
20132 KB |
Output is correct |
62 |
Correct |
117 ms |
20132 KB |
Output is correct |
63 |
Correct |
66 ms |
15880 KB |
Output is correct |
64 |
Correct |
79 ms |
17572 KB |
Output is correct |
65 |
Correct |
104 ms |
20200 KB |
Output is correct |
66 |
Correct |
100 ms |
20172 KB |
Output is correct |
67 |
Correct |
102 ms |
20060 KB |
Output is correct |
68 |
Correct |
63 ms |
15436 KB |
Output is correct |
69 |
Correct |
93 ms |
18340 KB |
Output is correct |
70 |
Correct |
68 ms |
16056 KB |
Output is correct |
71 |
Correct |
61 ms |
15548 KB |
Output is correct |
72 |
Correct |
62 ms |
15536 KB |
Output is correct |
73 |
Correct |
63 ms |
15540 KB |
Output is correct |
74 |
Correct |
65 ms |
15548 KB |
Output is correct |
75 |
Correct |
62 ms |
15436 KB |
Output is correct |
76 |
Correct |
62 ms |
15544 KB |
Output is correct |
77 |
Correct |
57 ms |
15540 KB |
Output is correct |
78 |
Correct |
72 ms |
15800 KB |
Output is correct |
79 |
Correct |
113 ms |
20132 KB |
Output is correct |
80 |
Correct |
78 ms |
16672 KB |
Output is correct |
81 |
Correct |
107 ms |
19112 KB |
Output is correct |
82 |
Correct |
112 ms |
20132 KB |
Output is correct |
83 |
Correct |
118 ms |
20264 KB |
Output is correct |
84 |
Correct |
105 ms |
20032 KB |
Output is correct |
85 |
Correct |
64 ms |
15548 KB |
Output is correct |
86 |
Correct |
64 ms |
15552 KB |
Output is correct |
87 |
Correct |
58 ms |
15456 KB |
Output is correct |
88 |
Correct |
98 ms |
20132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
11 ms |
2536 KB |
Output is correct |
9 |
Incorrect |
11 ms |
2652 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
11 ms |
2536 KB |
Output is correct |
9 |
Incorrect |
11 ms |
2652 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
41 ms |
15556 KB |
Output is correct |
3 |
Correct |
40 ms |
15552 KB |
Output is correct |
4 |
Correct |
54 ms |
15496 KB |
Output is correct |
5 |
Correct |
50 ms |
15540 KB |
Output is correct |
6 |
Correct |
49 ms |
15544 KB |
Output is correct |
7 |
Correct |
50 ms |
15540 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
62 ms |
15352 KB |
Output is correct |
11 |
Correct |
48 ms |
15552 KB |
Output is correct |
12 |
Correct |
47 ms |
15540 KB |
Output is correct |
13 |
Correct |
48 ms |
15444 KB |
Output is correct |
14 |
Correct |
65 ms |
15548 KB |
Output is correct |
15 |
Correct |
61 ms |
15540 KB |
Output is correct |
16 |
Correct |
60 ms |
15552 KB |
Output is correct |
17 |
Correct |
62 ms |
15544 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
64 ms |
15544 KB |
Output is correct |
20 |
Correct |
66 ms |
15540 KB |
Output is correct |
21 |
Correct |
64 ms |
15540 KB |
Output is correct |
22 |
Correct |
64 ms |
15540 KB |
Output is correct |
23 |
Correct |
63 ms |
15548 KB |
Output is correct |
24 |
Correct |
70 ms |
15552 KB |
Output is correct |
25 |
Correct |
64 ms |
15540 KB |
Output is correct |
26 |
Correct |
60 ms |
15572 KB |
Output is correct |
27 |
Correct |
58 ms |
15540 KB |
Output is correct |
28 |
Correct |
61 ms |
15544 KB |
Output is correct |
29 |
Correct |
63 ms |
15436 KB |
Output is correct |
30 |
Correct |
61 ms |
15384 KB |
Output is correct |
31 |
Correct |
74 ms |
15388 KB |
Output is correct |
32 |
Correct |
65 ms |
15516 KB |
Output is correct |
33 |
Correct |
62 ms |
15496 KB |
Output is correct |
34 |
Correct |
64 ms |
15552 KB |
Output is correct |
35 |
Correct |
63 ms |
15548 KB |
Output is correct |
36 |
Correct |
62 ms |
15548 KB |
Output is correct |
37 |
Correct |
61 ms |
15548 KB |
Output is correct |
38 |
Correct |
61 ms |
15540 KB |
Output is correct |
39 |
Correct |
64 ms |
15560 KB |
Output is correct |
40 |
Correct |
66 ms |
15540 KB |
Output is correct |
41 |
Correct |
68 ms |
15544 KB |
Output is correct |
42 |
Correct |
63 ms |
15544 KB |
Output is correct |
43 |
Correct |
67 ms |
15436 KB |
Output is correct |
44 |
Correct |
66 ms |
15572 KB |
Output is correct |
45 |
Correct |
67 ms |
15544 KB |
Output is correct |
46 |
Correct |
68 ms |
15548 KB |
Output is correct |
47 |
Correct |
67 ms |
15552 KB |
Output is correct |
48 |
Correct |
68 ms |
15544 KB |
Output is correct |
49 |
Correct |
65 ms |
15548 KB |
Output is correct |
50 |
Correct |
66 ms |
15544 KB |
Output is correct |
51 |
Correct |
87 ms |
15540 KB |
Output is correct |
52 |
Correct |
57 ms |
15792 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
67 ms |
15808 KB |
Output is correct |
55 |
Correct |
66 ms |
15796 KB |
Output is correct |
56 |
Correct |
100 ms |
16808 KB |
Output is correct |
57 |
Correct |
107 ms |
20156 KB |
Output is correct |
58 |
Correct |
103 ms |
20160 KB |
Output is correct |
59 |
Correct |
103 ms |
20188 KB |
Output is correct |
60 |
Correct |
77 ms |
17828 KB |
Output is correct |
61 |
Correct |
101 ms |
20132 KB |
Output is correct |
62 |
Correct |
117 ms |
20132 KB |
Output is correct |
63 |
Correct |
66 ms |
15880 KB |
Output is correct |
64 |
Correct |
79 ms |
17572 KB |
Output is correct |
65 |
Correct |
104 ms |
20200 KB |
Output is correct |
66 |
Correct |
100 ms |
20172 KB |
Output is correct |
67 |
Correct |
102 ms |
20060 KB |
Output is correct |
68 |
Correct |
63 ms |
15436 KB |
Output is correct |
69 |
Correct |
93 ms |
18340 KB |
Output is correct |
70 |
Correct |
68 ms |
16056 KB |
Output is correct |
71 |
Correct |
61 ms |
15548 KB |
Output is correct |
72 |
Correct |
62 ms |
15536 KB |
Output is correct |
73 |
Correct |
63 ms |
15540 KB |
Output is correct |
74 |
Correct |
65 ms |
15548 KB |
Output is correct |
75 |
Correct |
62 ms |
15436 KB |
Output is correct |
76 |
Correct |
62 ms |
15544 KB |
Output is correct |
77 |
Correct |
57 ms |
15540 KB |
Output is correct |
78 |
Correct |
72 ms |
15800 KB |
Output is correct |
79 |
Correct |
113 ms |
20132 KB |
Output is correct |
80 |
Correct |
78 ms |
16672 KB |
Output is correct |
81 |
Correct |
107 ms |
19112 KB |
Output is correct |
82 |
Correct |
112 ms |
20132 KB |
Output is correct |
83 |
Correct |
118 ms |
20264 KB |
Output is correct |
84 |
Correct |
105 ms |
20032 KB |
Output is correct |
85 |
Correct |
64 ms |
15548 KB |
Output is correct |
86 |
Correct |
64 ms |
15552 KB |
Output is correct |
87 |
Correct |
58 ms |
15456 KB |
Output is correct |
88 |
Correct |
98 ms |
20132 KB |
Output is correct |
89 |
Correct |
1 ms |
600 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
0 ms |
348 KB |
Output is correct |
93 |
Correct |
0 ms |
348 KB |
Output is correct |
94 |
Correct |
0 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
11 ms |
2536 KB |
Output is correct |
97 |
Incorrect |
11 ms |
2652 KB |
Output isn't correct |
98 |
Halted |
0 ms |
0 KB |
- |