Submission #959041

# Submission time Handle Problem Language Result Execution time Memory
959041 2024-04-07T12:14:00 Z kim Security Guard (JOI23_guard) C++17
100 / 100
212 ms 31136 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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 64 ms 18196 KB Output is correct
3 Correct 65 ms 19156 KB Output is correct
4 Correct 78 ms 18892 KB Output is correct
5 Correct 78 ms 18384 KB Output is correct
6 Correct 78 ms 18508 KB Output is correct
7 Correct 79 ms 18624 KB Output is correct
8 Correct 2 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 64 ms 18196 KB Output is correct
3 Correct 65 ms 19156 KB Output is correct
4 Correct 78 ms 18892 KB Output is correct
5 Correct 78 ms 18384 KB Output is correct
6 Correct 78 ms 18508 KB Output is correct
7 Correct 79 ms 18624 KB Output is correct
8 Correct 2 ms 7256 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 117 ms 21140 KB Output is correct
11 Correct 73 ms 20212 KB Output is correct
12 Correct 66 ms 20024 KB Output is correct
13 Correct 71 ms 19664 KB Output is correct
14 Correct 115 ms 19652 KB Output is correct
15 Correct 115 ms 20428 KB Output is correct
16 Correct 118 ms 19640 KB Output is correct
17 Correct 123 ms 20448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 64 ms 18196 KB Output is correct
3 Correct 65 ms 19156 KB Output is correct
4 Correct 78 ms 18892 KB Output is correct
5 Correct 78 ms 18384 KB Output is correct
6 Correct 78 ms 18508 KB Output is correct
7 Correct 79 ms 18624 KB Output is correct
8 Correct 2 ms 7256 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 117 ms 21140 KB Output is correct
11 Correct 73 ms 20212 KB Output is correct
12 Correct 66 ms 20024 KB Output is correct
13 Correct 71 ms 19664 KB Output is correct
14 Correct 115 ms 19652 KB Output is correct
15 Correct 115 ms 20428 KB Output is correct
16 Correct 118 ms 19640 KB Output is correct
17 Correct 123 ms 20448 KB Output is correct
18 Correct 2 ms 7256 KB Output is correct
19 Correct 124 ms 20168 KB Output is correct
20 Correct 132 ms 20428 KB Output is correct
21 Correct 134 ms 19648 KB Output is correct
22 Correct 127 ms 20432 KB Output is correct
23 Correct 137 ms 21044 KB Output is correct
24 Correct 119 ms 20432 KB Output is correct
25 Correct 112 ms 19992 KB Output is correct
26 Correct 118 ms 19656 KB Output is correct
27 Correct 103 ms 20944 KB Output is correct
28 Correct 123 ms 20696 KB Output is correct
29 Correct 134 ms 20428 KB Output is correct
30 Correct 112 ms 19992 KB Output is correct
31 Correct 100 ms 21200 KB Output is correct
32 Correct 155 ms 20432 KB Output is correct
33 Correct 109 ms 20104 KB Output is correct
34 Correct 112 ms 19924 KB Output is correct
35 Correct 113 ms 20528 KB Output is correct
36 Correct 98 ms 20016 KB Output is correct
37 Correct 98 ms 20676 KB Output is correct
38 Correct 111 ms 20900 KB Output is correct
39 Correct 89 ms 20176 KB Output is correct
40 Correct 103 ms 21108 KB Output is correct
41 Correct 94 ms 20436 KB Output is correct
42 Correct 99 ms 19256 KB Output is correct
43 Correct 130 ms 19648 KB Output is correct
44 Correct 140 ms 19664 KB Output is correct
45 Correct 131 ms 20732 KB Output is correct
46 Correct 119 ms 21124 KB Output is correct
47 Correct 123 ms 21240 KB Output is correct
48 Correct 126 ms 19652 KB Output is correct
49 Correct 122 ms 19992 KB Output is correct
50 Correct 129 ms 19752 KB Output is correct
51 Correct 109 ms 20624 KB Output is correct
52 Correct 99 ms 18116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 64 ms 18196 KB Output is correct
3 Correct 65 ms 19156 KB Output is correct
4 Correct 78 ms 18892 KB Output is correct
5 Correct 78 ms 18384 KB Output is correct
6 Correct 78 ms 18508 KB Output is correct
7 Correct 79 ms 18624 KB Output is correct
8 Correct 2 ms 7256 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 117 ms 21140 KB Output is correct
11 Correct 73 ms 20212 KB Output is correct
12 Correct 66 ms 20024 KB Output is correct
13 Correct 71 ms 19664 KB Output is correct
14 Correct 115 ms 19652 KB Output is correct
15 Correct 115 ms 20428 KB Output is correct
16 Correct 118 ms 19640 KB Output is correct
17 Correct 123 ms 20448 KB Output is correct
18 Correct 2 ms 7256 KB Output is correct
19 Correct 124 ms 20168 KB Output is correct
20 Correct 132 ms 20428 KB Output is correct
21 Correct 134 ms 19648 KB Output is correct
22 Correct 127 ms 20432 KB Output is correct
23 Correct 137 ms 21044 KB Output is correct
24 Correct 119 ms 20432 KB Output is correct
25 Correct 112 ms 19992 KB Output is correct
26 Correct 118 ms 19656 KB Output is correct
27 Correct 103 ms 20944 KB Output is correct
28 Correct 123 ms 20696 KB Output is correct
29 Correct 134 ms 20428 KB Output is correct
30 Correct 112 ms 19992 KB Output is correct
31 Correct 100 ms 21200 KB Output is correct
32 Correct 155 ms 20432 KB Output is correct
33 Correct 109 ms 20104 KB Output is correct
34 Correct 112 ms 19924 KB Output is correct
35 Correct 113 ms 20528 KB Output is correct
36 Correct 98 ms 20016 KB Output is correct
37 Correct 98 ms 20676 KB Output is correct
38 Correct 111 ms 20900 KB Output is correct
39 Correct 89 ms 20176 KB Output is correct
40 Correct 103 ms 21108 KB Output is correct
41 Correct 94 ms 20436 KB Output is correct
42 Correct 99 ms 19256 KB Output is correct
43 Correct 130 ms 19648 KB Output is correct
44 Correct 140 ms 19664 KB Output is correct
45 Correct 131 ms 20732 KB Output is correct
46 Correct 119 ms 21124 KB Output is correct
47 Correct 123 ms 21240 KB Output is correct
48 Correct 126 ms 19652 KB Output is correct
49 Correct 122 ms 19992 KB Output is correct
50 Correct 129 ms 19752 KB Output is correct
51 Correct 109 ms 20624 KB Output is correct
52 Correct 99 ms 18116 KB Output is correct
53 Correct 2 ms 7260 KB Output is correct
54 Correct 140 ms 20400 KB Output is correct
55 Correct 139 ms 20964 KB Output is correct
56 Correct 141 ms 26404 KB Output is correct
57 Correct 206 ms 26776 KB Output is correct
58 Correct 183 ms 27684 KB Output is correct
59 Correct 177 ms 27128 KB Output is correct
60 Correct 160 ms 26788 KB Output is correct
61 Correct 191 ms 26332 KB Output is correct
62 Correct 153 ms 26300 KB Output is correct
63 Correct 148 ms 21336 KB Output is correct
64 Correct 146 ms 26296 KB Output is correct
65 Correct 177 ms 26948 KB Output is correct
66 Correct 154 ms 26324 KB Output is correct
67 Correct 211 ms 26400 KB Output is correct
68 Correct 107 ms 18996 KB Output is correct
69 Correct 146 ms 24860 KB Output is correct
70 Correct 131 ms 20408 KB Output is correct
71 Correct 100 ms 20276 KB Output is correct
72 Correct 98 ms 20180 KB Output is correct
73 Correct 110 ms 20164 KB Output is correct
74 Correct 95 ms 21108 KB Output is correct
75 Correct 95 ms 21196 KB Output is correct
76 Correct 96 ms 19632 KB Output is correct
77 Correct 117 ms 19892 KB Output is correct
78 Correct 122 ms 21108 KB Output is correct
79 Correct 196 ms 28072 KB Output is correct
80 Correct 165 ms 22312 KB Output is correct
81 Correct 177 ms 27032 KB Output is correct
82 Correct 177 ms 27804 KB Output is correct
83 Correct 198 ms 26292 KB Output is correct
84 Correct 179 ms 27940 KB Output is correct
85 Correct 126 ms 20000 KB Output is correct
86 Correct 106 ms 20144 KB Output is correct
87 Correct 126 ms 19292 KB Output is correct
88 Correct 204 ms 26388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7320 KB Output is correct
4 Correct 2 ms 7256 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 7256 KB Output is correct
8 Correct 17 ms 9516 KB Output is correct
9 Correct 15 ms 9308 KB Output is correct
10 Correct 18 ms 9304 KB Output is correct
11 Correct 14 ms 9308 KB Output is correct
12 Correct 15 ms 9304 KB Output is correct
13 Correct 15 ms 9304 KB Output is correct
14 Correct 14 ms 9308 KB Output is correct
15 Correct 19 ms 9304 KB Output is correct
16 Correct 16 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7320 KB Output is correct
4 Correct 2 ms 7256 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 7256 KB Output is correct
8 Correct 17 ms 9516 KB Output is correct
9 Correct 15 ms 9308 KB Output is correct
10 Correct 18 ms 9304 KB Output is correct
11 Correct 14 ms 9308 KB Output is correct
12 Correct 15 ms 9304 KB Output is correct
13 Correct 15 ms 9304 KB Output is correct
14 Correct 14 ms 9308 KB Output is correct
15 Correct 19 ms 9304 KB Output is correct
16 Correct 16 ms 9308 KB Output is correct
17 Correct 20 ms 9940 KB Output is correct
18 Correct 20 ms 9944 KB Output is correct
19 Correct 39 ms 11000 KB Output is correct
20 Correct 50 ms 12484 KB Output is correct
21 Correct 59 ms 13256 KB Output is correct
22 Correct 54 ms 12512 KB Output is correct
23 Correct 96 ms 16516 KB Output is correct
24 Correct 64 ms 13592 KB Output is correct
25 Correct 16 ms 9564 KB Output is correct
26 Correct 36 ms 11728 KB Output is correct
27 Correct 20 ms 10216 KB Output is correct
28 Correct 17 ms 9564 KB Output is correct
29 Correct 16 ms 9700 KB Output is correct
30 Correct 16 ms 9612 KB Output is correct
31 Correct 13 ms 8360 KB Output is correct
32 Correct 16 ms 8540 KB Output is correct
33 Correct 17 ms 9820 KB Output is correct
34 Correct 18 ms 9808 KB Output is correct
35 Correct 36 ms 11240 KB Output is correct
36 Correct 102 ms 17128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 64 ms 18196 KB Output is correct
3 Correct 65 ms 19156 KB Output is correct
4 Correct 78 ms 18892 KB Output is correct
5 Correct 78 ms 18384 KB Output is correct
6 Correct 78 ms 18508 KB Output is correct
7 Correct 79 ms 18624 KB Output is correct
8 Correct 2 ms 7256 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 117 ms 21140 KB Output is correct
11 Correct 73 ms 20212 KB Output is correct
12 Correct 66 ms 20024 KB Output is correct
13 Correct 71 ms 19664 KB Output is correct
14 Correct 115 ms 19652 KB Output is correct
15 Correct 115 ms 20428 KB Output is correct
16 Correct 118 ms 19640 KB Output is correct
17 Correct 123 ms 20448 KB Output is correct
18 Correct 2 ms 7256 KB Output is correct
19 Correct 124 ms 20168 KB Output is correct
20 Correct 132 ms 20428 KB Output is correct
21 Correct 134 ms 19648 KB Output is correct
22 Correct 127 ms 20432 KB Output is correct
23 Correct 137 ms 21044 KB Output is correct
24 Correct 119 ms 20432 KB Output is correct
25 Correct 112 ms 19992 KB Output is correct
26 Correct 118 ms 19656 KB Output is correct
27 Correct 103 ms 20944 KB Output is correct
28 Correct 123 ms 20696 KB Output is correct
29 Correct 134 ms 20428 KB Output is correct
30 Correct 112 ms 19992 KB Output is correct
31 Correct 100 ms 21200 KB Output is correct
32 Correct 155 ms 20432 KB Output is correct
33 Correct 109 ms 20104 KB Output is correct
34 Correct 112 ms 19924 KB Output is correct
35 Correct 113 ms 20528 KB Output is correct
36 Correct 98 ms 20016 KB Output is correct
37 Correct 98 ms 20676 KB Output is correct
38 Correct 111 ms 20900 KB Output is correct
39 Correct 89 ms 20176 KB Output is correct
40 Correct 103 ms 21108 KB Output is correct
41 Correct 94 ms 20436 KB Output is correct
42 Correct 99 ms 19256 KB Output is correct
43 Correct 130 ms 19648 KB Output is correct
44 Correct 140 ms 19664 KB Output is correct
45 Correct 131 ms 20732 KB Output is correct
46 Correct 119 ms 21124 KB Output is correct
47 Correct 123 ms 21240 KB Output is correct
48 Correct 126 ms 19652 KB Output is correct
49 Correct 122 ms 19992 KB Output is correct
50 Correct 129 ms 19752 KB Output is correct
51 Correct 109 ms 20624 KB Output is correct
52 Correct 99 ms 18116 KB Output is correct
53 Correct 2 ms 7260 KB Output is correct
54 Correct 140 ms 20400 KB Output is correct
55 Correct 139 ms 20964 KB Output is correct
56 Correct 141 ms 26404 KB Output is correct
57 Correct 206 ms 26776 KB Output is correct
58 Correct 183 ms 27684 KB Output is correct
59 Correct 177 ms 27128 KB Output is correct
60 Correct 160 ms 26788 KB Output is correct
61 Correct 191 ms 26332 KB Output is correct
62 Correct 153 ms 26300 KB Output is correct
63 Correct 148 ms 21336 KB Output is correct
64 Correct 146 ms 26296 KB Output is correct
65 Correct 177 ms 26948 KB Output is correct
66 Correct 154 ms 26324 KB Output is correct
67 Correct 211 ms 26400 KB Output is correct
68 Correct 107 ms 18996 KB Output is correct
69 Correct 146 ms 24860 KB Output is correct
70 Correct 131 ms 20408 KB Output is correct
71 Correct 100 ms 20276 KB Output is correct
72 Correct 98 ms 20180 KB Output is correct
73 Correct 110 ms 20164 KB Output is correct
74 Correct 95 ms 21108 KB Output is correct
75 Correct 95 ms 21196 KB Output is correct
76 Correct 96 ms 19632 KB Output is correct
77 Correct 117 ms 19892 KB Output is correct
78 Correct 122 ms 21108 KB Output is correct
79 Correct 196 ms 28072 KB Output is correct
80 Correct 165 ms 22312 KB Output is correct
81 Correct 177 ms 27032 KB Output is correct
82 Correct 177 ms 27804 KB Output is correct
83 Correct 198 ms 26292 KB Output is correct
84 Correct 179 ms 27940 KB Output is correct
85 Correct 126 ms 20000 KB Output is correct
86 Correct 106 ms 20144 KB Output is correct
87 Correct 126 ms 19292 KB Output is correct
88 Correct 204 ms 26388 KB Output is correct
89 Correct 1 ms 7256 KB Output is correct
90 Correct 2 ms 7260 KB Output is correct
91 Correct 2 ms 7320 KB Output is correct
92 Correct 2 ms 7256 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 7256 KB Output is correct
96 Correct 17 ms 9516 KB Output is correct
97 Correct 15 ms 9308 KB Output is correct
98 Correct 18 ms 9304 KB Output is correct
99 Correct 14 ms 9308 KB Output is correct
100 Correct 15 ms 9304 KB Output is correct
101 Correct 15 ms 9304 KB Output is correct
102 Correct 14 ms 9308 KB Output is correct
103 Correct 19 ms 9304 KB Output is correct
104 Correct 16 ms 9308 KB Output is correct
105 Correct 20 ms 9940 KB Output is correct
106 Correct 20 ms 9944 KB Output is correct
107 Correct 39 ms 11000 KB Output is correct
108 Correct 50 ms 12484 KB Output is correct
109 Correct 59 ms 13256 KB Output is correct
110 Correct 54 ms 12512 KB Output is correct
111 Correct 96 ms 16516 KB Output is correct
112 Correct 64 ms 13592 KB Output is correct
113 Correct 16 ms 9564 KB Output is correct
114 Correct 36 ms 11728 KB Output is correct
115 Correct 20 ms 10216 KB Output is correct
116 Correct 17 ms 9564 KB Output is correct
117 Correct 16 ms 9700 KB Output is correct
118 Correct 16 ms 9612 KB Output is correct
119 Correct 13 ms 8360 KB Output is correct
120 Correct 16 ms 8540 KB Output is correct
121 Correct 17 ms 9820 KB Output is correct
122 Correct 18 ms 9808 KB Output is correct
123 Correct 36 ms 11240 KB Output is correct
124 Correct 102 ms 17128 KB Output is correct
125 Correct 158 ms 23236 KB Output is correct
126 Correct 146 ms 22888 KB Output is correct
127 Correct 154 ms 24004 KB Output is correct
128 Correct 197 ms 30524 KB Output is correct
129 Correct 185 ms 29900 KB Output is correct
130 Correct 193 ms 29220 KB Output is correct
131 Correct 183 ms 29828 KB Output is correct
132 Correct 201 ms 29272 KB Output is correct
133 Correct 175 ms 30952 KB Output is correct
134 Correct 148 ms 23416 KB Output is correct
135 Correct 149 ms 24260 KB Output is correct
136 Correct 191 ms 29344 KB Output is correct
137 Correct 161 ms 29636 KB Output is correct
138 Correct 190 ms 29260 KB Output is correct
139 Correct 129 ms 21420 KB Output is correct
140 Correct 149 ms 28096 KB Output is correct
141 Correct 144 ms 23244 KB Output is correct
142 Correct 117 ms 23440 KB Output is correct
143 Correct 114 ms 23176 KB Output is correct
144 Correct 141 ms 22776 KB Output is correct
145 Correct 111 ms 22816 KB Output is correct
146 Correct 110 ms 23376 KB Output is correct
147 Correct 118 ms 22148 KB Output is correct
148 Correct 113 ms 21364 KB Output is correct
149 Correct 125 ms 22808 KB Output is correct
150 Correct 197 ms 29124 KB Output is correct
151 Correct 153 ms 24208 KB Output is correct
152 Correct 171 ms 29540 KB Output is correct
153 Correct 185 ms 31136 KB Output is correct
154 Correct 180 ms 29516 KB Output is correct
155 Correct 185 ms 29116 KB Output is correct
156 Correct 143 ms 23576 KB Output is correct
157 Correct 124 ms 24160 KB Output is correct
158 Correct 106 ms 20168 KB Output is correct
159 Correct 212 ms 29188 KB Output is correct