Submission #1030895

# Submission time Handle Problem Language Result Execution time Memory
1030895 2024-07-22T11:32:46 Z Unforgettablepl Security Guard (JOI23_guard) C++17
50 / 100
127 ms 23272 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

struct UFDS{
	vector<int> p,siz;
	UFDS(int n):p(n+1),siz(n+1,1){iota(p.begin(),p.end(),0);}
	int findRoot(int x){
		return p[x]==x ? x : p[x]=findRoot(p[x]);
	}
	bool unite(int a,int b){
		a = findRoot(a);
		b = findRoot(b);
		if(a==b)return false;
		if(siz[b]>siz[a])swap(a,b);
		siz[a]+=siz[b];
		p[b]=a;
		return true;
	}
};


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 ans = (*max_element(arr.begin(),arr.end()));
	for(int i=1;i<=n;i++){
		ans-=arr[i];
	}
	UFDS dsu(n);
	for(int i=0;i<m;i++){
		auto [cost,a,b] = edges[i];
		if(dsu.unite(a,b)){
			ans+=cost;
		}
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 44 ms 10380 KB Output is correct
3 Correct 50 ms 9924 KB Output is correct
4 Correct 46 ms 10676 KB Output is correct
5 Correct 44 ms 9676 KB Output is correct
6 Correct 45 ms 10952 KB Output is correct
7 Correct 46 ms 10944 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 44 ms 10380 KB Output is correct
3 Correct 50 ms 9924 KB Output is correct
4 Correct 46 ms 10676 KB Output is correct
5 Correct 44 ms 9676 KB Output is correct
6 Correct 45 ms 10952 KB Output is correct
7 Correct 46 ms 10944 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 55 ms 10860 KB Output is correct
11 Correct 42 ms 9672 KB Output is correct
12 Correct 39 ms 10432 KB Output is correct
13 Correct 39 ms 10108 KB Output is correct
14 Correct 52 ms 9664 KB Output is correct
15 Correct 56 ms 10180 KB Output is correct
16 Correct 54 ms 9668 KB Output is correct
17 Correct 68 ms 10932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 44 ms 10380 KB Output is correct
3 Correct 50 ms 9924 KB Output is correct
4 Correct 46 ms 10676 KB Output is correct
5 Correct 44 ms 9676 KB Output is correct
6 Correct 45 ms 10952 KB Output is correct
7 Correct 46 ms 10944 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 55 ms 10860 KB Output is correct
11 Correct 42 ms 9672 KB Output is correct
12 Correct 39 ms 10432 KB Output is correct
13 Correct 39 ms 10108 KB Output is correct
14 Correct 52 ms 9664 KB Output is correct
15 Correct 56 ms 10180 KB Output is correct
16 Correct 54 ms 9668 KB Output is correct
17 Correct 68 ms 10932 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 57 ms 9932 KB Output is correct
20 Correct 57 ms 9920 KB Output is correct
21 Correct 56 ms 10172 KB Output is correct
22 Correct 56 ms 11196 KB Output is correct
23 Correct 67 ms 9920 KB Output is correct
24 Correct 53 ms 9924 KB Output is correct
25 Correct 53 ms 9664 KB Output is correct
26 Correct 56 ms 10920 KB Output is correct
27 Correct 58 ms 9644 KB Output is correct
28 Correct 56 ms 9676 KB Output is correct
29 Correct 55 ms 10428 KB Output is correct
30 Correct 56 ms 10676 KB Output is correct
31 Correct 54 ms 10684 KB Output is correct
32 Correct 59 ms 9664 KB Output is correct
33 Correct 56 ms 9816 KB Output is correct
34 Correct 58 ms 10172 KB Output is correct
35 Correct 58 ms 11096 KB Output is correct
36 Correct 58 ms 10796 KB Output is correct
37 Correct 58 ms 9668 KB Output is correct
38 Correct 68 ms 9812 KB Output is correct
39 Correct 54 ms 9668 KB Output is correct
40 Correct 56 ms 10976 KB Output is correct
41 Correct 53 ms 11084 KB Output is correct
42 Correct 53 ms 10680 KB Output is correct
43 Correct 60 ms 10060 KB Output is correct
44 Correct 58 ms 10172 KB Output is correct
45 Correct 68 ms 10572 KB Output is correct
46 Correct 61 ms 9676 KB Output is correct
47 Correct 73 ms 9664 KB Output is correct
48 Correct 60 ms 9668 KB Output is correct
49 Correct 54 ms 9932 KB Output is correct
50 Correct 58 ms 10176 KB Output is correct
51 Correct 59 ms 9660 KB Output is correct
52 Correct 52 ms 9716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 44 ms 10380 KB Output is correct
3 Correct 50 ms 9924 KB Output is correct
4 Correct 46 ms 10676 KB Output is correct
5 Correct 44 ms 9676 KB Output is correct
6 Correct 45 ms 10952 KB Output is correct
7 Correct 46 ms 10944 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 55 ms 10860 KB Output is correct
11 Correct 42 ms 9672 KB Output is correct
12 Correct 39 ms 10432 KB Output is correct
13 Correct 39 ms 10108 KB Output is correct
14 Correct 52 ms 9664 KB Output is correct
15 Correct 56 ms 10180 KB Output is correct
16 Correct 54 ms 9668 KB Output is correct
17 Correct 68 ms 10932 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 57 ms 9932 KB Output is correct
20 Correct 57 ms 9920 KB Output is correct
21 Correct 56 ms 10172 KB Output is correct
22 Correct 56 ms 11196 KB Output is correct
23 Correct 67 ms 9920 KB Output is correct
24 Correct 53 ms 9924 KB Output is correct
25 Correct 53 ms 9664 KB Output is correct
26 Correct 56 ms 10920 KB Output is correct
27 Correct 58 ms 9644 KB Output is correct
28 Correct 56 ms 9676 KB Output is correct
29 Correct 55 ms 10428 KB Output is correct
30 Correct 56 ms 10676 KB Output is correct
31 Correct 54 ms 10684 KB Output is correct
32 Correct 59 ms 9664 KB Output is correct
33 Correct 56 ms 9816 KB Output is correct
34 Correct 58 ms 10172 KB Output is correct
35 Correct 58 ms 11096 KB Output is correct
36 Correct 58 ms 10796 KB Output is correct
37 Correct 58 ms 9668 KB Output is correct
38 Correct 68 ms 9812 KB Output is correct
39 Correct 54 ms 9668 KB Output is correct
40 Correct 56 ms 10976 KB Output is correct
41 Correct 53 ms 11084 KB Output is correct
42 Correct 53 ms 10680 KB Output is correct
43 Correct 60 ms 10060 KB Output is correct
44 Correct 58 ms 10172 KB Output is correct
45 Correct 68 ms 10572 KB Output is correct
46 Correct 61 ms 9676 KB Output is correct
47 Correct 73 ms 9664 KB Output is correct
48 Correct 60 ms 9668 KB Output is correct
49 Correct 54 ms 9932 KB Output is correct
50 Correct 58 ms 10176 KB Output is correct
51 Correct 59 ms 9660 KB Output is correct
52 Correct 52 ms 9716 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 59 ms 9916 KB Output is correct
55 Correct 66 ms 15440 KB Output is correct
56 Correct 81 ms 20556 KB Output is correct
57 Correct 100 ms 23220 KB Output is correct
58 Correct 97 ms 21424 KB Output is correct
59 Correct 103 ms 23272 KB Output is correct
60 Correct 80 ms 21444 KB Output is correct
61 Correct 127 ms 22908 KB Output is correct
62 Correct 95 ms 21660 KB Output is correct
63 Correct 83 ms 14524 KB Output is correct
64 Correct 77 ms 21180 KB Output is correct
65 Correct 97 ms 21416 KB Output is correct
66 Correct 102 ms 22964 KB Output is correct
67 Correct 96 ms 22456 KB Output is correct
68 Correct 58 ms 14780 KB Output is correct
69 Correct 87 ms 21432 KB Output is correct
70 Correct 70 ms 15288 KB Output is correct
71 Correct 61 ms 15032 KB Output is correct
72 Correct 61 ms 15540 KB Output is correct
73 Correct 70 ms 14776 KB Output is correct
74 Correct 56 ms 14540 KB Output is correct
75 Correct 59 ms 14492 KB Output is correct
76 Correct 56 ms 14016 KB Output is correct
77 Correct 53 ms 13504 KB Output is correct
78 Correct 72 ms 15028 KB Output is correct
79 Correct 104 ms 21928 KB Output is correct
80 Correct 74 ms 16316 KB Output is correct
81 Correct 104 ms 21304 KB Output is correct
82 Correct 108 ms 21680 KB Output is correct
83 Correct 104 ms 23164 KB Output is correct
84 Correct 97 ms 22964 KB Output is correct
85 Correct 58 ms 15176 KB Output is correct
86 Correct 61 ms 14888 KB Output is correct
87 Correct 54 ms 13496 KB Output is correct
88 Correct 98 ms 22192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 44 ms 10380 KB Output is correct
3 Correct 50 ms 9924 KB Output is correct
4 Correct 46 ms 10676 KB Output is correct
5 Correct 44 ms 9676 KB Output is correct
6 Correct 45 ms 10952 KB Output is correct
7 Correct 46 ms 10944 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 55 ms 10860 KB Output is correct
11 Correct 42 ms 9672 KB Output is correct
12 Correct 39 ms 10432 KB Output is correct
13 Correct 39 ms 10108 KB Output is correct
14 Correct 52 ms 9664 KB Output is correct
15 Correct 56 ms 10180 KB Output is correct
16 Correct 54 ms 9668 KB Output is correct
17 Correct 68 ms 10932 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 57 ms 9932 KB Output is correct
20 Correct 57 ms 9920 KB Output is correct
21 Correct 56 ms 10172 KB Output is correct
22 Correct 56 ms 11196 KB Output is correct
23 Correct 67 ms 9920 KB Output is correct
24 Correct 53 ms 9924 KB Output is correct
25 Correct 53 ms 9664 KB Output is correct
26 Correct 56 ms 10920 KB Output is correct
27 Correct 58 ms 9644 KB Output is correct
28 Correct 56 ms 9676 KB Output is correct
29 Correct 55 ms 10428 KB Output is correct
30 Correct 56 ms 10676 KB Output is correct
31 Correct 54 ms 10684 KB Output is correct
32 Correct 59 ms 9664 KB Output is correct
33 Correct 56 ms 9816 KB Output is correct
34 Correct 58 ms 10172 KB Output is correct
35 Correct 58 ms 11096 KB Output is correct
36 Correct 58 ms 10796 KB Output is correct
37 Correct 58 ms 9668 KB Output is correct
38 Correct 68 ms 9812 KB Output is correct
39 Correct 54 ms 9668 KB Output is correct
40 Correct 56 ms 10976 KB Output is correct
41 Correct 53 ms 11084 KB Output is correct
42 Correct 53 ms 10680 KB Output is correct
43 Correct 60 ms 10060 KB Output is correct
44 Correct 58 ms 10172 KB Output is correct
45 Correct 68 ms 10572 KB Output is correct
46 Correct 61 ms 9676 KB Output is correct
47 Correct 73 ms 9664 KB Output is correct
48 Correct 60 ms 9668 KB Output is correct
49 Correct 54 ms 9932 KB Output is correct
50 Correct 58 ms 10176 KB Output is correct
51 Correct 59 ms 9660 KB Output is correct
52 Correct 52 ms 9716 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 59 ms 9916 KB Output is correct
55 Correct 66 ms 15440 KB Output is correct
56 Correct 81 ms 20556 KB Output is correct
57 Correct 100 ms 23220 KB Output is correct
58 Correct 97 ms 21424 KB Output is correct
59 Correct 103 ms 23272 KB Output is correct
60 Correct 80 ms 21444 KB Output is correct
61 Correct 127 ms 22908 KB Output is correct
62 Correct 95 ms 21660 KB Output is correct
63 Correct 83 ms 14524 KB Output is correct
64 Correct 77 ms 21180 KB Output is correct
65 Correct 97 ms 21416 KB Output is correct
66 Correct 102 ms 22964 KB Output is correct
67 Correct 96 ms 22456 KB Output is correct
68 Correct 58 ms 14780 KB Output is correct
69 Correct 87 ms 21432 KB Output is correct
70 Correct 70 ms 15288 KB Output is correct
71 Correct 61 ms 15032 KB Output is correct
72 Correct 61 ms 15540 KB Output is correct
73 Correct 70 ms 14776 KB Output is correct
74 Correct 56 ms 14540 KB Output is correct
75 Correct 59 ms 14492 KB Output is correct
76 Correct 56 ms 14016 KB Output is correct
77 Correct 53 ms 13504 KB Output is correct
78 Correct 72 ms 15028 KB Output is correct
79 Correct 104 ms 21928 KB Output is correct
80 Correct 74 ms 16316 KB Output is correct
81 Correct 104 ms 21304 KB Output is correct
82 Correct 108 ms 21680 KB Output is correct
83 Correct 104 ms 23164 KB Output is correct
84 Correct 97 ms 22964 KB Output is correct
85 Correct 58 ms 15176 KB Output is correct
86 Correct 61 ms 14888 KB Output is correct
87 Correct 54 ms 13496 KB Output is correct
88 Correct 98 ms 22192 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Incorrect 0 ms 348 KB Output isn't correct
91 Halted 0 ms 0 KB -