답안 #796074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796074 2023-07-28T05:49:06 Z 박상훈(#10069) Security Guard (JOI23_guard) C++17
37 / 100
418 ms 26856 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF2 = 4e18;

vector<int> adj[200200];
int a[200200], chk[200200];
ll ans;

void dfs(int s, int pa){
	ans += a[pa];
	for (auto &v:adj[s]) if (v!=pa) dfs(v, s);
}

int main(){
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);

	for (int i=1;i<=n;i++) scanf("%d", a+i);
	int root = max_element(a+1, a+n+1) - a;
	
	for (int i=1;i<=m;i++){
		int x, y;
		scanf("%d %d", &x, &y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	if (q > 0) q = 0;

	ans = 0;
	
	multiset<pair<ll, int>> st;
	for (int i=1;i<=n;i++) if (i!=root) st.emplace(a[i], i);

	for (auto &x:adj[root]) chk[x] = 1;

	while(!st.empty()){
		auto [mn, root2] = *st.begin(); st.erase(st.begin());
		
		multiset<pair<ll, int>> pq;
		pq.emplace(mn, root2);
		ll cst = 0, cst2 = INF2;
		vector<int> V;

		while(!pq.empty()){
			auto [val, s] = *pq.begin(); pq.erase(pq.begin());
			V.push_back(s);

			for (auto &v:adj[s]) if (st.find(pair<ll, int>(a[v], v)) != st.end()){
				st.erase(st.find(pair<ll, int>(a[v], v)));
				cst += val;

				pq.emplace(a[v], v);
			}
		}

		for (auto &x:V) if (chk[x]) cst2 = min(cst2, -mn + a[x]);
		assert(cst2 < INF2);

		ans += a[root] + cst + cst2;
	}

	printf("%lld\n", ans);
}

Compilation message

guard.cpp: In function 'int main()':
guard.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d %d %d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
guard.cpp:21:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  for (int i=1;i<=n;i++) scanf("%d", a+i);
      |                         ~~~~~^~~~~~~~~~~
guard.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%d %d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 129 ms 24428 KB Output is correct
3 Correct 129 ms 24520 KB Output is correct
4 Correct 113 ms 24544 KB Output is correct
5 Correct 112 ms 24440 KB Output is correct
6 Correct 111 ms 24472 KB Output is correct
7 Correct 128 ms 24548 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 129 ms 24428 KB Output is correct
3 Correct 129 ms 24520 KB Output is correct
4 Correct 113 ms 24544 KB Output is correct
5 Correct 112 ms 24440 KB Output is correct
6 Correct 111 ms 24472 KB Output is correct
7 Correct 128 ms 24548 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 211 ms 24468 KB Output is correct
11 Correct 139 ms 24488 KB Output is correct
12 Correct 132 ms 24524 KB Output is correct
13 Correct 132 ms 24544 KB Output is correct
14 Correct 219 ms 24488 KB Output is correct
15 Correct 215 ms 24668 KB Output is correct
16 Correct 229 ms 24452 KB Output is correct
17 Correct 212 ms 24560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 129 ms 24428 KB Output is correct
3 Correct 129 ms 24520 KB Output is correct
4 Correct 113 ms 24544 KB Output is correct
5 Correct 112 ms 24440 KB Output is correct
6 Correct 111 ms 24472 KB Output is correct
7 Correct 128 ms 24548 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 211 ms 24468 KB Output is correct
11 Correct 139 ms 24488 KB Output is correct
12 Correct 132 ms 24524 KB Output is correct
13 Correct 132 ms 24544 KB Output is correct
14 Correct 219 ms 24488 KB Output is correct
15 Correct 215 ms 24668 KB Output is correct
16 Correct 229 ms 24452 KB Output is correct
17 Correct 212 ms 24560 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 367 ms 25696 KB Output is correct
20 Correct 328 ms 25644 KB Output is correct
21 Correct 368 ms 25716 KB Output is correct
22 Correct 351 ms 25888 KB Output is correct
23 Correct 356 ms 26644 KB Output is correct
24 Correct 341 ms 26744 KB Output is correct
25 Correct 343 ms 26540 KB Output is correct
26 Correct 376 ms 26428 KB Output is correct
27 Correct 320 ms 26812 KB Output is correct
28 Correct 326 ms 25772 KB Output is correct
29 Correct 354 ms 25664 KB Output is correct
30 Correct 334 ms 26168 KB Output is correct
31 Correct 325 ms 26856 KB Output is correct
32 Correct 418 ms 26320 KB Output is correct
33 Correct 304 ms 25288 KB Output is correct
34 Correct 309 ms 25784 KB Output is correct
35 Correct 298 ms 26652 KB Output is correct
36 Correct 278 ms 26768 KB Output is correct
37 Correct 281 ms 26744 KB Output is correct
38 Correct 252 ms 26104 KB Output is correct
39 Correct 255 ms 26048 KB Output is correct
40 Correct 269 ms 25844 KB Output is correct
41 Correct 224 ms 25676 KB Output is correct
42 Correct 238 ms 25668 KB Output is correct
43 Correct 317 ms 25964 KB Output is correct
44 Correct 399 ms 25896 KB Output is correct
45 Correct 340 ms 26036 KB Output is correct
46 Correct 354 ms 25956 KB Output is correct
47 Correct 366 ms 25968 KB Output is correct
48 Correct 354 ms 25852 KB Output is correct
49 Correct 269 ms 26124 KB Output is correct
50 Correct 269 ms 25648 KB Output is correct
51 Correct 356 ms 25944 KB Output is correct
52 Correct 319 ms 25864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 129 ms 24428 KB Output is correct
3 Correct 129 ms 24520 KB Output is correct
4 Correct 113 ms 24544 KB Output is correct
5 Correct 112 ms 24440 KB Output is correct
6 Correct 111 ms 24472 KB Output is correct
7 Correct 128 ms 24548 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 211 ms 24468 KB Output is correct
11 Correct 139 ms 24488 KB Output is correct
12 Correct 132 ms 24524 KB Output is correct
13 Correct 132 ms 24544 KB Output is correct
14 Correct 219 ms 24488 KB Output is correct
15 Correct 215 ms 24668 KB Output is correct
16 Correct 229 ms 24452 KB Output is correct
17 Correct 212 ms 24560 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 367 ms 25696 KB Output is correct
20 Correct 328 ms 25644 KB Output is correct
21 Correct 368 ms 25716 KB Output is correct
22 Correct 351 ms 25888 KB Output is correct
23 Correct 356 ms 26644 KB Output is correct
24 Correct 341 ms 26744 KB Output is correct
25 Correct 343 ms 26540 KB Output is correct
26 Correct 376 ms 26428 KB Output is correct
27 Correct 320 ms 26812 KB Output is correct
28 Correct 326 ms 25772 KB Output is correct
29 Correct 354 ms 25664 KB Output is correct
30 Correct 334 ms 26168 KB Output is correct
31 Correct 325 ms 26856 KB Output is correct
32 Correct 418 ms 26320 KB Output is correct
33 Correct 304 ms 25288 KB Output is correct
34 Correct 309 ms 25784 KB Output is correct
35 Correct 298 ms 26652 KB Output is correct
36 Correct 278 ms 26768 KB Output is correct
37 Correct 281 ms 26744 KB Output is correct
38 Correct 252 ms 26104 KB Output is correct
39 Correct 255 ms 26048 KB Output is correct
40 Correct 269 ms 25844 KB Output is correct
41 Correct 224 ms 25676 KB Output is correct
42 Correct 238 ms 25668 KB Output is correct
43 Correct 317 ms 25964 KB Output is correct
44 Correct 399 ms 25896 KB Output is correct
45 Correct 340 ms 26036 KB Output is correct
46 Correct 354 ms 25956 KB Output is correct
47 Correct 366 ms 25968 KB Output is correct
48 Correct 354 ms 25852 KB Output is correct
49 Correct 269 ms 26124 KB Output is correct
50 Correct 269 ms 25648 KB Output is correct
51 Correct 356 ms 25944 KB Output is correct
52 Correct 319 ms 25864 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Incorrect 361 ms 26188 KB Output isn't correct
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 3 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 3 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 129 ms 24428 KB Output is correct
3 Correct 129 ms 24520 KB Output is correct
4 Correct 113 ms 24544 KB Output is correct
5 Correct 112 ms 24440 KB Output is correct
6 Correct 111 ms 24472 KB Output is correct
7 Correct 128 ms 24548 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 211 ms 24468 KB Output is correct
11 Correct 139 ms 24488 KB Output is correct
12 Correct 132 ms 24524 KB Output is correct
13 Correct 132 ms 24544 KB Output is correct
14 Correct 219 ms 24488 KB Output is correct
15 Correct 215 ms 24668 KB Output is correct
16 Correct 229 ms 24452 KB Output is correct
17 Correct 212 ms 24560 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 367 ms 25696 KB Output is correct
20 Correct 328 ms 25644 KB Output is correct
21 Correct 368 ms 25716 KB Output is correct
22 Correct 351 ms 25888 KB Output is correct
23 Correct 356 ms 26644 KB Output is correct
24 Correct 341 ms 26744 KB Output is correct
25 Correct 343 ms 26540 KB Output is correct
26 Correct 376 ms 26428 KB Output is correct
27 Correct 320 ms 26812 KB Output is correct
28 Correct 326 ms 25772 KB Output is correct
29 Correct 354 ms 25664 KB Output is correct
30 Correct 334 ms 26168 KB Output is correct
31 Correct 325 ms 26856 KB Output is correct
32 Correct 418 ms 26320 KB Output is correct
33 Correct 304 ms 25288 KB Output is correct
34 Correct 309 ms 25784 KB Output is correct
35 Correct 298 ms 26652 KB Output is correct
36 Correct 278 ms 26768 KB Output is correct
37 Correct 281 ms 26744 KB Output is correct
38 Correct 252 ms 26104 KB Output is correct
39 Correct 255 ms 26048 KB Output is correct
40 Correct 269 ms 25844 KB Output is correct
41 Correct 224 ms 25676 KB Output is correct
42 Correct 238 ms 25668 KB Output is correct
43 Correct 317 ms 25964 KB Output is correct
44 Correct 399 ms 25896 KB Output is correct
45 Correct 340 ms 26036 KB Output is correct
46 Correct 354 ms 25956 KB Output is correct
47 Correct 366 ms 25968 KB Output is correct
48 Correct 354 ms 25852 KB Output is correct
49 Correct 269 ms 26124 KB Output is correct
50 Correct 269 ms 25648 KB Output is correct
51 Correct 356 ms 25944 KB Output is correct
52 Correct 319 ms 25864 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Incorrect 361 ms 26188 KB Output isn't correct
55 Halted 0 ms 0 KB -