답안 #958941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958941 2024-04-07T08:25:30 Z kim Security Guard (JOI23_guard) C++17
100 / 100
241 ms 31228 KB
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll=long long;
using pii=pair<int,int>;
#define f first
#define s second

vector<int> adj[200005];
int a[200005],p[200005],mn[200005];
int fSet(int u){
	if(p[u]==u) return u;
	return p[u]=fSet(p[u]);
}
bool uSet(int u,int v){
	int U=fSet(u), V=fSet(v);
	if(U==V) return 0;
	p[U]=V;
	mn[V]=min(mn[U],mn[V]);
	return 1;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);

	int n,m,Q; cin>>n>>m>>Q;
	int mn=1,mx=1;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		p[i]=i;
		::mn[i]=a[i];
		if(a[i]<a[mn]) mn=i;
		if(a[i]>a[mx]) mx=i;
	}
	vector<pii> edge,edge2;
	for(int i=0;i<m;++i){
		int u,v; cin>>u>>v;
		edge.eb(u,v);
	}
	sort(edge.begin(),edge.end(),[&](const pii &l,const pii &r){
		return a[l.f]+a[l.s]<a[r.f]+a[r.s];
	});

	stack<ll> ans;
	ll cur=1LL*a[mn]*(n-1)+a[mx]-a[mn];
	ans.emplace(cur);
	for(auto &[u,v]:edge){
		if(fSet(u)==fSet(v)) continue;
		uSet(u,v);
		edge2.eb(u,v);
	}
	for(int i=1;i<=n;++i) p[i]=i, ::mn[i]=a[i];
	for(auto &[u,v]:edge2){
		if(u==mn||v==mn) uSet(u,v);
	}
	using A=tuple<ll,int,int>;
	priority_queue<A,vector<A>,greater<A>> pq;
	for(auto &[u,v]:edge2){
		if(u!=mn&&v!=mn) pq.emplace(a[u]-a[v]-a[mn]-max(::mn[fSet(u)],::mn[fSet(v)]),u,v);
	}
	while(pq.size()){
		auto [w,u,v]=pq.top(); pq.pop();
		int U=fSet(u),V=fSet(v);
		if(U==V) continue;
		if(max(::mn[U],::mn[V])!=a[u]+a[v]-a[mn]-w) pq.emplace(a[u]+a[v]-a[mn]-max(::mn[U],::mn[V]),u,v);
		else{
			cur+=w;
			ans.emplace(cur);
			uSet(u,v);
		}
	}

	cout<<cur<<'\n';
	while(Q--){
		if(ans.size()>1) ans.pop();
		cout<<ans.top()<<'\n';
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 86 ms 18100 KB Output is correct
3 Correct 78 ms 18388 KB Output is correct
4 Correct 111 ms 18432 KB Output is correct
5 Correct 106 ms 19148 KB Output is correct
6 Correct 100 ms 19664 KB Output is correct
7 Correct 100 ms 19664 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 86 ms 18100 KB Output is correct
3 Correct 78 ms 18388 KB Output is correct
4 Correct 111 ms 18432 KB Output is correct
5 Correct 106 ms 19148 KB Output is correct
6 Correct 100 ms 19664 KB Output is correct
7 Correct 100 ms 19664 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 144 ms 20812 KB Output is correct
11 Correct 89 ms 20888 KB Output is correct
12 Correct 99 ms 20256 KB Output is correct
13 Correct 87 ms 20176 KB Output is correct
14 Correct 142 ms 20512 KB Output is correct
15 Correct 143 ms 20824 KB Output is correct
16 Correct 151 ms 19908 KB Output is correct
17 Correct 144 ms 19912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 86 ms 18100 KB Output is correct
3 Correct 78 ms 18388 KB Output is correct
4 Correct 111 ms 18432 KB Output is correct
5 Correct 106 ms 19148 KB Output is correct
6 Correct 100 ms 19664 KB Output is correct
7 Correct 100 ms 19664 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 144 ms 20812 KB Output is correct
11 Correct 89 ms 20888 KB Output is correct
12 Correct 99 ms 20256 KB Output is correct
13 Correct 87 ms 20176 KB Output is correct
14 Correct 142 ms 20512 KB Output is correct
15 Correct 143 ms 20824 KB Output is correct
16 Correct 151 ms 19908 KB Output is correct
17 Correct 144 ms 19912 KB Output is correct
18 Correct 2 ms 7260 KB Output is correct
19 Correct 155 ms 19648 KB Output is correct
20 Correct 167 ms 20036 KB Output is correct
21 Correct 160 ms 21032 KB Output is correct
22 Correct 171 ms 19628 KB Output is correct
23 Correct 157 ms 20432 KB Output is correct
24 Correct 146 ms 20160 KB Output is correct
25 Correct 154 ms 19920 KB Output is correct
26 Correct 143 ms 21092 KB Output is correct
27 Correct 132 ms 19696 KB Output is correct
28 Correct 176 ms 20940 KB Output is correct
29 Correct 176 ms 20076 KB Output is correct
30 Correct 146 ms 21052 KB Output is correct
31 Correct 133 ms 19920 KB Output is correct
32 Correct 159 ms 21288 KB Output is correct
33 Correct 147 ms 18992 KB Output is correct
34 Correct 153 ms 21108 KB Output is correct
35 Correct 143 ms 20780 KB Output is correct
36 Correct 127 ms 20272 KB Output is correct
37 Correct 132 ms 20032 KB Output is correct
38 Correct 154 ms 20948 KB Output is correct
39 Correct 127 ms 20724 KB Output is correct
40 Correct 131 ms 20472 KB Output is correct
41 Correct 123 ms 20048 KB Output is correct
42 Correct 112 ms 19148 KB Output is correct
43 Correct 163 ms 20692 KB Output is correct
44 Correct 173 ms 20432 KB Output is correct
45 Correct 159 ms 19920 KB Output is correct
46 Correct 156 ms 20428 KB Output is correct
47 Correct 167 ms 21180 KB Output is correct
48 Correct 168 ms 19652 KB Output is correct
49 Correct 145 ms 20004 KB Output is correct
50 Correct 148 ms 20180 KB Output is correct
51 Correct 135 ms 20172 KB Output is correct
52 Correct 126 ms 18640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 86 ms 18100 KB Output is correct
3 Correct 78 ms 18388 KB Output is correct
4 Correct 111 ms 18432 KB Output is correct
5 Correct 106 ms 19148 KB Output is correct
6 Correct 100 ms 19664 KB Output is correct
7 Correct 100 ms 19664 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 144 ms 20812 KB Output is correct
11 Correct 89 ms 20888 KB Output is correct
12 Correct 99 ms 20256 KB Output is correct
13 Correct 87 ms 20176 KB Output is correct
14 Correct 142 ms 20512 KB Output is correct
15 Correct 143 ms 20824 KB Output is correct
16 Correct 151 ms 19908 KB Output is correct
17 Correct 144 ms 19912 KB Output is correct
18 Correct 2 ms 7260 KB Output is correct
19 Correct 155 ms 19648 KB Output is correct
20 Correct 167 ms 20036 KB Output is correct
21 Correct 160 ms 21032 KB Output is correct
22 Correct 171 ms 19628 KB Output is correct
23 Correct 157 ms 20432 KB Output is correct
24 Correct 146 ms 20160 KB Output is correct
25 Correct 154 ms 19920 KB Output is correct
26 Correct 143 ms 21092 KB Output is correct
27 Correct 132 ms 19696 KB Output is correct
28 Correct 176 ms 20940 KB Output is correct
29 Correct 176 ms 20076 KB Output is correct
30 Correct 146 ms 21052 KB Output is correct
31 Correct 133 ms 19920 KB Output is correct
32 Correct 159 ms 21288 KB Output is correct
33 Correct 147 ms 18992 KB Output is correct
34 Correct 153 ms 21108 KB Output is correct
35 Correct 143 ms 20780 KB Output is correct
36 Correct 127 ms 20272 KB Output is correct
37 Correct 132 ms 20032 KB Output is correct
38 Correct 154 ms 20948 KB Output is correct
39 Correct 127 ms 20724 KB Output is correct
40 Correct 131 ms 20472 KB Output is correct
41 Correct 123 ms 20048 KB Output is correct
42 Correct 112 ms 19148 KB Output is correct
43 Correct 163 ms 20692 KB Output is correct
44 Correct 173 ms 20432 KB Output is correct
45 Correct 159 ms 19920 KB Output is correct
46 Correct 156 ms 20428 KB Output is correct
47 Correct 167 ms 21180 KB Output is correct
48 Correct 168 ms 19652 KB Output is correct
49 Correct 145 ms 20004 KB Output is correct
50 Correct 148 ms 20180 KB Output is correct
51 Correct 135 ms 20172 KB Output is correct
52 Correct 126 ms 18640 KB Output is correct
53 Correct 2 ms 7260 KB Output is correct
54 Correct 169 ms 20400 KB Output is correct
55 Correct 158 ms 19992 KB Output is correct
56 Correct 182 ms 24256 KB Output is correct
57 Correct 213 ms 26452 KB Output is correct
58 Correct 232 ms 26816 KB Output is correct
59 Correct 230 ms 27280 KB Output is correct
60 Correct 175 ms 25452 KB Output is correct
61 Correct 194 ms 27328 KB Output is correct
62 Correct 191 ms 26532 KB Output is correct
63 Correct 164 ms 20944 KB Output is correct
64 Correct 194 ms 26008 KB Output is correct
65 Correct 205 ms 27796 KB Output is correct
66 Correct 179 ms 26212 KB Output is correct
67 Correct 210 ms 26396 KB Output is correct
68 Correct 143 ms 19012 KB Output is correct
69 Correct 172 ms 26792 KB Output is correct
70 Correct 152 ms 21452 KB Output is correct
71 Correct 127 ms 20008 KB Output is correct
72 Correct 140 ms 20780 KB Output is correct
73 Correct 135 ms 20004 KB Output is correct
74 Correct 119 ms 20352 KB Output is correct
75 Correct 150 ms 20332 KB Output is correct
76 Correct 116 ms 20412 KB Output is correct
77 Correct 124 ms 19576 KB Output is correct
78 Correct 169 ms 20944 KB Output is correct
79 Correct 238 ms 26220 KB Output is correct
80 Correct 176 ms 21020 KB Output is correct
81 Correct 194 ms 25668 KB Output is correct
82 Correct 217 ms 26456 KB Output is correct
83 Correct 211 ms 26444 KB Output is correct
84 Correct 188 ms 26416 KB Output is correct
85 Correct 148 ms 20572 KB Output is correct
86 Correct 128 ms 20264 KB Output is correct
87 Correct 122 ms 18720 KB Output is correct
88 Correct 217 ms 26388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 16 ms 9444 KB Output is correct
9 Correct 15 ms 9508 KB Output is correct
10 Correct 14 ms 9304 KB Output is correct
11 Correct 15 ms 9308 KB Output is correct
12 Correct 15 ms 9308 KB Output is correct
13 Correct 19 ms 9380 KB Output is correct
14 Correct 15 ms 9304 KB Output is correct
15 Correct 15 ms 9304 KB Output is correct
16 Correct 15 ms 9464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 16 ms 9444 KB Output is correct
9 Correct 15 ms 9508 KB Output is correct
10 Correct 14 ms 9304 KB Output is correct
11 Correct 15 ms 9308 KB Output is correct
12 Correct 15 ms 9308 KB Output is correct
13 Correct 19 ms 9380 KB Output is correct
14 Correct 15 ms 9304 KB Output is correct
15 Correct 15 ms 9304 KB Output is correct
16 Correct 15 ms 9464 KB Output is correct
17 Correct 21 ms 9948 KB Output is correct
18 Correct 21 ms 10032 KB Output is correct
19 Correct 32 ms 11000 KB Output is correct
20 Correct 49 ms 12484 KB Output is correct
21 Correct 63 ms 13364 KB Output is correct
22 Correct 51 ms 12532 KB Output is correct
23 Correct 99 ms 16328 KB Output is correct
24 Correct 64 ms 13764 KB Output is correct
25 Correct 16 ms 9560 KB Output is correct
26 Correct 39 ms 11800 KB Output is correct
27 Correct 20 ms 10196 KB Output is correct
28 Correct 16 ms 9788 KB Output is correct
29 Correct 17 ms 9564 KB Output is correct
30 Correct 20 ms 9680 KB Output is correct
31 Correct 14 ms 8536 KB Output is correct
32 Correct 14 ms 8540 KB Output is correct
33 Correct 17 ms 9820 KB Output is correct
34 Correct 17 ms 9820 KB Output is correct
35 Correct 34 ms 11216 KB Output is correct
36 Correct 115 ms 16316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 86 ms 18100 KB Output is correct
3 Correct 78 ms 18388 KB Output is correct
4 Correct 111 ms 18432 KB Output is correct
5 Correct 106 ms 19148 KB Output is correct
6 Correct 100 ms 19664 KB Output is correct
7 Correct 100 ms 19664 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 144 ms 20812 KB Output is correct
11 Correct 89 ms 20888 KB Output is correct
12 Correct 99 ms 20256 KB Output is correct
13 Correct 87 ms 20176 KB Output is correct
14 Correct 142 ms 20512 KB Output is correct
15 Correct 143 ms 20824 KB Output is correct
16 Correct 151 ms 19908 KB Output is correct
17 Correct 144 ms 19912 KB Output is correct
18 Correct 2 ms 7260 KB Output is correct
19 Correct 155 ms 19648 KB Output is correct
20 Correct 167 ms 20036 KB Output is correct
21 Correct 160 ms 21032 KB Output is correct
22 Correct 171 ms 19628 KB Output is correct
23 Correct 157 ms 20432 KB Output is correct
24 Correct 146 ms 20160 KB Output is correct
25 Correct 154 ms 19920 KB Output is correct
26 Correct 143 ms 21092 KB Output is correct
27 Correct 132 ms 19696 KB Output is correct
28 Correct 176 ms 20940 KB Output is correct
29 Correct 176 ms 20076 KB Output is correct
30 Correct 146 ms 21052 KB Output is correct
31 Correct 133 ms 19920 KB Output is correct
32 Correct 159 ms 21288 KB Output is correct
33 Correct 147 ms 18992 KB Output is correct
34 Correct 153 ms 21108 KB Output is correct
35 Correct 143 ms 20780 KB Output is correct
36 Correct 127 ms 20272 KB Output is correct
37 Correct 132 ms 20032 KB Output is correct
38 Correct 154 ms 20948 KB Output is correct
39 Correct 127 ms 20724 KB Output is correct
40 Correct 131 ms 20472 KB Output is correct
41 Correct 123 ms 20048 KB Output is correct
42 Correct 112 ms 19148 KB Output is correct
43 Correct 163 ms 20692 KB Output is correct
44 Correct 173 ms 20432 KB Output is correct
45 Correct 159 ms 19920 KB Output is correct
46 Correct 156 ms 20428 KB Output is correct
47 Correct 167 ms 21180 KB Output is correct
48 Correct 168 ms 19652 KB Output is correct
49 Correct 145 ms 20004 KB Output is correct
50 Correct 148 ms 20180 KB Output is correct
51 Correct 135 ms 20172 KB Output is correct
52 Correct 126 ms 18640 KB Output is correct
53 Correct 2 ms 7260 KB Output is correct
54 Correct 169 ms 20400 KB Output is correct
55 Correct 158 ms 19992 KB Output is correct
56 Correct 182 ms 24256 KB Output is correct
57 Correct 213 ms 26452 KB Output is correct
58 Correct 232 ms 26816 KB Output is correct
59 Correct 230 ms 27280 KB Output is correct
60 Correct 175 ms 25452 KB Output is correct
61 Correct 194 ms 27328 KB Output is correct
62 Correct 191 ms 26532 KB Output is correct
63 Correct 164 ms 20944 KB Output is correct
64 Correct 194 ms 26008 KB Output is correct
65 Correct 205 ms 27796 KB Output is correct
66 Correct 179 ms 26212 KB Output is correct
67 Correct 210 ms 26396 KB Output is correct
68 Correct 143 ms 19012 KB Output is correct
69 Correct 172 ms 26792 KB Output is correct
70 Correct 152 ms 21452 KB Output is correct
71 Correct 127 ms 20008 KB Output is correct
72 Correct 140 ms 20780 KB Output is correct
73 Correct 135 ms 20004 KB Output is correct
74 Correct 119 ms 20352 KB Output is correct
75 Correct 150 ms 20332 KB Output is correct
76 Correct 116 ms 20412 KB Output is correct
77 Correct 124 ms 19576 KB Output is correct
78 Correct 169 ms 20944 KB Output is correct
79 Correct 238 ms 26220 KB Output is correct
80 Correct 176 ms 21020 KB Output is correct
81 Correct 194 ms 25668 KB Output is correct
82 Correct 217 ms 26456 KB Output is correct
83 Correct 211 ms 26444 KB Output is correct
84 Correct 188 ms 26416 KB Output is correct
85 Correct 148 ms 20572 KB Output is correct
86 Correct 128 ms 20264 KB Output is correct
87 Correct 122 ms 18720 KB Output is correct
88 Correct 217 ms 26388 KB Output is correct
89 Correct 2 ms 7260 KB Output is correct
90 Correct 2 ms 7260 KB Output is correct
91 Correct 2 ms 7260 KB Output is correct
92 Correct 2 ms 7260 KB Output is correct
93 Correct 2 ms 7260 KB Output is correct
94 Correct 2 ms 7260 KB Output is correct
95 Correct 2 ms 7260 KB Output is correct
96 Correct 16 ms 9444 KB Output is correct
97 Correct 15 ms 9508 KB Output is correct
98 Correct 14 ms 9304 KB Output is correct
99 Correct 15 ms 9308 KB Output is correct
100 Correct 15 ms 9308 KB Output is correct
101 Correct 19 ms 9380 KB Output is correct
102 Correct 15 ms 9304 KB Output is correct
103 Correct 15 ms 9304 KB Output is correct
104 Correct 15 ms 9464 KB Output is correct
105 Correct 21 ms 9948 KB Output is correct
106 Correct 21 ms 10032 KB Output is correct
107 Correct 32 ms 11000 KB Output is correct
108 Correct 49 ms 12484 KB Output is correct
109 Correct 63 ms 13364 KB Output is correct
110 Correct 51 ms 12532 KB Output is correct
111 Correct 99 ms 16328 KB Output is correct
112 Correct 64 ms 13764 KB Output is correct
113 Correct 16 ms 9560 KB Output is correct
114 Correct 39 ms 11800 KB Output is correct
115 Correct 20 ms 10196 KB Output is correct
116 Correct 16 ms 9788 KB Output is correct
117 Correct 17 ms 9564 KB Output is correct
118 Correct 20 ms 9680 KB Output is correct
119 Correct 14 ms 8536 KB Output is correct
120 Correct 14 ms 8540 KB Output is correct
121 Correct 17 ms 9820 KB Output is correct
122 Correct 17 ms 9820 KB Output is correct
123 Correct 34 ms 11216 KB Output is correct
124 Correct 115 ms 16316 KB Output is correct
125 Correct 178 ms 23524 KB Output is correct
126 Correct 182 ms 23508 KB Output is correct
127 Correct 189 ms 24256 KB Output is correct
128 Correct 224 ms 29120 KB Output is correct
129 Correct 206 ms 29192 KB Output is correct
130 Correct 223 ms 29588 KB Output is correct
131 Correct 211 ms 29624 KB Output is correct
132 Correct 211 ms 29420 KB Output is correct
133 Correct 223 ms 29392 KB Output is correct
134 Correct 178 ms 23236 KB Output is correct
135 Correct 201 ms 25032 KB Output is correct
136 Correct 219 ms 30616 KB Output is correct
137 Correct 201 ms 30392 KB Output is correct
138 Correct 236 ms 30704 KB Output is correct
139 Correct 175 ms 21692 KB Output is correct
140 Correct 184 ms 30148 KB Output is correct
141 Correct 160 ms 23376 KB Output is correct
142 Correct 149 ms 23604 KB Output is correct
143 Correct 152 ms 23404 KB Output is correct
144 Correct 145 ms 22880 KB Output is correct
145 Correct 132 ms 23196 KB Output is correct
146 Correct 138 ms 22448 KB Output is correct
147 Correct 125 ms 21696 KB Output is correct
148 Correct 126 ms 22188 KB Output is correct
149 Correct 163 ms 23316 KB Output is correct
150 Correct 241 ms 29712 KB Output is correct
151 Correct 178 ms 24196 KB Output is correct
152 Correct 234 ms 29372 KB Output is correct
153 Correct 218 ms 30388 KB Output is correct
154 Correct 222 ms 31228 KB Output is correct
155 Correct 219 ms 29276 KB Output is correct
156 Correct 160 ms 23236 KB Output is correct
157 Correct 153 ms 23864 KB Output is correct
158 Correct 132 ms 19580 KB Output is correct
159 Correct 234 ms 30180 KB Output is correct