Submission #1030911

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

#define int long long

struct UFDS{
	vector<int> p,siz,mini;
	int sigma,compo;
	UFDS(int n,vector<int> arr):p(n+1),siz(n+1,1),mini(n+1),sigma(0),compo(n){
		iota(p.begin(),p.end(),0);
		mini=arr;
		for(int i=1;i<=n;i++){
			sigma+=arr[i];
		}
	}
	int findRoot(int x){
		return p[x]==x ? x : p[x]=findRoot(p[x]);
	}
	int getans(int minima){
		return sigma+(compo-2ll)*minima;
	}
	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);
		int maxi = max(mini[a],mini[b]);
		mini[a]=min(mini[a],mini[b]);
		sigma-=maxi;
		siz[a]+=siz[b];
		p[b]=a;
		compo--;
		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 baseans = (*max_element(arr.begin(),arr.end()));
	for(int i=1;i<=n;i++){
		baseans-=arr[i];
	}
	UFDS dsu(n,arr);
	vector<int> ans(n);
	int minima = *min_element(arr.begin()+1,arr.end());
	ans[0] = dsu.getans(minima);
	int iter = 1;
	int offset = 0;
	for(int i=0;i<m;i++){
		auto [cost,a,b] = edges[i];
		if(dsu.unite(a,b)){
			offset+=cost;
			ans[iter++]=offset+dsu.getans(minima);
		}
	}
	for(int i=0;i<=q;i++){
		cout << baseans+ans[max(0ll,n-1ll-i)] << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 39 ms 13000 KB Output is correct
3 Correct 38 ms 12884 KB Output is correct
4 Correct 46 ms 13056 KB Output is correct
5 Correct 46 ms 12988 KB Output is correct
6 Correct 51 ms 12896 KB Output is correct
7 Correct 48 ms 13760 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 39 ms 13000 KB Output is correct
3 Correct 38 ms 12884 KB Output is correct
4 Correct 46 ms 13056 KB Output is correct
5 Correct 46 ms 12988 KB Output is correct
6 Correct 51 ms 12896 KB Output is correct
7 Correct 48 ms 13760 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 57 ms 13628 KB Output is correct
11 Correct 46 ms 14268 KB Output is correct
12 Correct 41 ms 13244 KB Output is correct
13 Correct 40 ms 13000 KB Output is correct
14 Correct 63 ms 13924 KB Output is correct
15 Correct 59 ms 13524 KB Output is correct
16 Correct 57 ms 12988 KB Output is correct
17 Correct 57 ms 13504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 39 ms 13000 KB Output is correct
3 Correct 38 ms 12884 KB Output is correct
4 Correct 46 ms 13056 KB Output is correct
5 Correct 46 ms 12988 KB Output is correct
6 Correct 51 ms 12896 KB Output is correct
7 Correct 48 ms 13760 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 57 ms 13628 KB Output is correct
11 Correct 46 ms 14268 KB Output is correct
12 Correct 41 ms 13244 KB Output is correct
13 Correct 40 ms 13000 KB Output is correct
14 Correct 63 ms 13924 KB Output is correct
15 Correct 59 ms 13524 KB Output is correct
16 Correct 57 ms 12988 KB Output is correct
17 Correct 57 ms 13504 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 60 ms 13620 KB Output is correct
20 Correct 60 ms 12884 KB Output is correct
21 Correct 62 ms 14016 KB Output is correct
22 Correct 61 ms 13752 KB Output is correct
23 Correct 58 ms 12732 KB Output is correct
24 Correct 56 ms 13488 KB Output is correct
25 Correct 68 ms 14100 KB Output is correct
26 Correct 56 ms 12984 KB Output is correct
27 Correct 55 ms 13244 KB Output is correct
28 Correct 61 ms 13496 KB Output is correct
29 Correct 59 ms 12996 KB Output is correct
30 Correct 69 ms 13920 KB Output is correct
31 Correct 59 ms 13492 KB Output is correct
32 Correct 58 ms 13756 KB Output is correct
33 Correct 60 ms 13752 KB Output is correct
34 Correct 59 ms 13752 KB Output is correct
35 Correct 60 ms 12780 KB Output is correct
36 Correct 72 ms 13748 KB Output is correct
37 Correct 59 ms 13812 KB Output is correct
38 Correct 64 ms 12728 KB Output is correct
39 Correct 56 ms 14216 KB Output is correct
40 Correct 60 ms 13248 KB Output is correct
41 Correct 55 ms 14272 KB Output is correct
42 Correct 54 ms 12964 KB Output is correct
43 Correct 67 ms 14008 KB Output is correct
44 Correct 61 ms 14012 KB Output is correct
45 Correct 64 ms 12968 KB Output is correct
46 Correct 64 ms 13484 KB Output is correct
47 Correct 67 ms 12780 KB Output is correct
48 Correct 66 ms 12960 KB Output is correct
49 Correct 58 ms 12916 KB Output is correct
50 Correct 59 ms 12988 KB Output is correct
51 Correct 63 ms 14268 KB Output is correct
52 Correct 60 ms 13888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 39 ms 13000 KB Output is correct
3 Correct 38 ms 12884 KB Output is correct
4 Correct 46 ms 13056 KB Output is correct
5 Correct 46 ms 12988 KB Output is correct
6 Correct 51 ms 12896 KB Output is correct
7 Correct 48 ms 13760 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 57 ms 13628 KB Output is correct
11 Correct 46 ms 14268 KB Output is correct
12 Correct 41 ms 13244 KB Output is correct
13 Correct 40 ms 13000 KB Output is correct
14 Correct 63 ms 13924 KB Output is correct
15 Correct 59 ms 13524 KB Output is correct
16 Correct 57 ms 12988 KB Output is correct
17 Correct 57 ms 13504 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 60 ms 13620 KB Output is correct
20 Correct 60 ms 12884 KB Output is correct
21 Correct 62 ms 14016 KB Output is correct
22 Correct 61 ms 13752 KB Output is correct
23 Correct 58 ms 12732 KB Output is correct
24 Correct 56 ms 13488 KB Output is correct
25 Correct 68 ms 14100 KB Output is correct
26 Correct 56 ms 12984 KB Output is correct
27 Correct 55 ms 13244 KB Output is correct
28 Correct 61 ms 13496 KB Output is correct
29 Correct 59 ms 12996 KB Output is correct
30 Correct 69 ms 13920 KB Output is correct
31 Correct 59 ms 13492 KB Output is correct
32 Correct 58 ms 13756 KB Output is correct
33 Correct 60 ms 13752 KB Output is correct
34 Correct 59 ms 13752 KB Output is correct
35 Correct 60 ms 12780 KB Output is correct
36 Correct 72 ms 13748 KB Output is correct
37 Correct 59 ms 13812 KB Output is correct
38 Correct 64 ms 12728 KB Output is correct
39 Correct 56 ms 14216 KB Output is correct
40 Correct 60 ms 13248 KB Output is correct
41 Correct 55 ms 14272 KB Output is correct
42 Correct 54 ms 12964 KB Output is correct
43 Correct 67 ms 14008 KB Output is correct
44 Correct 61 ms 14012 KB Output is correct
45 Correct 64 ms 12968 KB Output is correct
46 Correct 64 ms 13484 KB Output is correct
47 Correct 67 ms 12780 KB Output is correct
48 Correct 66 ms 12960 KB Output is correct
49 Correct 58 ms 12916 KB Output is correct
50 Correct 59 ms 12988 KB Output is correct
51 Correct 63 ms 14268 KB Output is correct
52 Correct 60 ms 13888 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 74 ms 13508 KB Output is correct
55 Correct 61 ms 13236 KB Output is correct
56 Correct 75 ms 15864 KB Output is correct
57 Correct 95 ms 18864 KB Output is correct
58 Correct 103 ms 18860 KB Output is correct
59 Correct 98 ms 19296 KB Output is correct
60 Correct 78 ms 16564 KB Output is correct
61 Correct 101 ms 18864 KB Output is correct
62 Correct 98 ms 17464 KB Output is correct
63 Correct 70 ms 14100 KB Output is correct
64 Correct 77 ms 16568 KB Output is correct
65 Correct 96 ms 19132 KB Output is correct
66 Correct 95 ms 19376 KB Output is correct
67 Correct 103 ms 18864 KB Output is correct
68 Correct 61 ms 12732 KB Output is correct
69 Correct 88 ms 16316 KB Output is correct
70 Correct 66 ms 13396 KB Output is correct
71 Correct 60 ms 12852 KB Output is correct
72 Correct 60 ms 14004 KB Output is correct
73 Correct 67 ms 12728 KB Output is correct
74 Correct 60 ms 13296 KB Output is correct
75 Correct 58 ms 12732 KB Output is correct
76 Correct 60 ms 12736 KB Output is correct
77 Correct 62 ms 13848 KB Output is correct
78 Correct 73 ms 14272 KB Output is correct
79 Correct 103 ms 17640 KB Output is correct
80 Correct 76 ms 14004 KB Output is correct
81 Correct 101 ms 17920 KB Output is correct
82 Correct 108 ms 19120 KB Output is correct
83 Correct 108 ms 18008 KB Output is correct
84 Correct 96 ms 19444 KB Output is correct
85 Correct 60 ms 14004 KB Output is correct
86 Correct 62 ms 13752 KB Output is correct
87 Correct 55 ms 13744 KB Output is correct
88 Correct 102 ms 19632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 39 ms 13000 KB Output is correct
3 Correct 38 ms 12884 KB Output is correct
4 Correct 46 ms 13056 KB Output is correct
5 Correct 46 ms 12988 KB Output is correct
6 Correct 51 ms 12896 KB Output is correct
7 Correct 48 ms 13760 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 57 ms 13628 KB Output is correct
11 Correct 46 ms 14268 KB Output is correct
12 Correct 41 ms 13244 KB Output is correct
13 Correct 40 ms 13000 KB Output is correct
14 Correct 63 ms 13924 KB Output is correct
15 Correct 59 ms 13524 KB Output is correct
16 Correct 57 ms 12988 KB Output is correct
17 Correct 57 ms 13504 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 60 ms 13620 KB Output is correct
20 Correct 60 ms 12884 KB Output is correct
21 Correct 62 ms 14016 KB Output is correct
22 Correct 61 ms 13752 KB Output is correct
23 Correct 58 ms 12732 KB Output is correct
24 Correct 56 ms 13488 KB Output is correct
25 Correct 68 ms 14100 KB Output is correct
26 Correct 56 ms 12984 KB Output is correct
27 Correct 55 ms 13244 KB Output is correct
28 Correct 61 ms 13496 KB Output is correct
29 Correct 59 ms 12996 KB Output is correct
30 Correct 69 ms 13920 KB Output is correct
31 Correct 59 ms 13492 KB Output is correct
32 Correct 58 ms 13756 KB Output is correct
33 Correct 60 ms 13752 KB Output is correct
34 Correct 59 ms 13752 KB Output is correct
35 Correct 60 ms 12780 KB Output is correct
36 Correct 72 ms 13748 KB Output is correct
37 Correct 59 ms 13812 KB Output is correct
38 Correct 64 ms 12728 KB Output is correct
39 Correct 56 ms 14216 KB Output is correct
40 Correct 60 ms 13248 KB Output is correct
41 Correct 55 ms 14272 KB Output is correct
42 Correct 54 ms 12964 KB Output is correct
43 Correct 67 ms 14008 KB Output is correct
44 Correct 61 ms 14012 KB Output is correct
45 Correct 64 ms 12968 KB Output is correct
46 Correct 64 ms 13484 KB Output is correct
47 Correct 67 ms 12780 KB Output is correct
48 Correct 66 ms 12960 KB Output is correct
49 Correct 58 ms 12916 KB Output is correct
50 Correct 59 ms 12988 KB Output is correct
51 Correct 63 ms 14268 KB Output is correct
52 Correct 60 ms 13888 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 74 ms 13508 KB Output is correct
55 Correct 61 ms 13236 KB Output is correct
56 Correct 75 ms 15864 KB Output is correct
57 Correct 95 ms 18864 KB Output is correct
58 Correct 103 ms 18860 KB Output is correct
59 Correct 98 ms 19296 KB Output is correct
60 Correct 78 ms 16564 KB Output is correct
61 Correct 101 ms 18864 KB Output is correct
62 Correct 98 ms 17464 KB Output is correct
63 Correct 70 ms 14100 KB Output is correct
64 Correct 77 ms 16568 KB Output is correct
65 Correct 96 ms 19132 KB Output is correct
66 Correct 95 ms 19376 KB Output is correct
67 Correct 103 ms 18864 KB Output is correct
68 Correct 61 ms 12732 KB Output is correct
69 Correct 88 ms 16316 KB Output is correct
70 Correct 66 ms 13396 KB Output is correct
71 Correct 60 ms 12852 KB Output is correct
72 Correct 60 ms 14004 KB Output is correct
73 Correct 67 ms 12728 KB Output is correct
74 Correct 60 ms 13296 KB Output is correct
75 Correct 58 ms 12732 KB Output is correct
76 Correct 60 ms 12736 KB Output is correct
77 Correct 62 ms 13848 KB Output is correct
78 Correct 73 ms 14272 KB Output is correct
79 Correct 103 ms 17640 KB Output is correct
80 Correct 76 ms 14004 KB Output is correct
81 Correct 101 ms 17920 KB Output is correct
82 Correct 108 ms 19120 KB Output is correct
83 Correct 108 ms 18008 KB Output is correct
84 Correct 96 ms 19444 KB Output is correct
85 Correct 60 ms 14004 KB Output is correct
86 Correct 62 ms 13752 KB Output is correct
87 Correct 55 ms 13744 KB Output is correct
88 Correct 102 ms 19632 KB Output is correct
89 Correct 1 ms 348 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 1 ms 348 KB Output is correct
93 Correct 0 ms 348 KB Output is correct
94 Incorrect 0 ms 348 KB Output isn't correct
95 Halted 0 ms 0 KB -