Submission #796750

# Submission time Handle Problem Language Result Execution time Memory
796750 2023-07-28T16:58:59 Z ToniB Stranded Far From Home (BOI22_island) C++17
100 / 100
179 ms 37256 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 2;

int n, m, s[MAXN], uf[MAXN], sz[MAXN];
ll sum[MAXN];
vector<int> adj[MAXN], d[MAXN];
vector<pair<int, int> > v;
bool bio[MAXN], ans[MAXN];

int f(int x){
	while(uf[x] != -1) x = uf[x];
	return x;
}
void join(int u, int v, bool good){
	if(u == v) return ;
	if(sz[u] > sz[v]){
		swap(u, v);
		swap(d[u], d[v]);
	}
	uf[u] = v;
	sz[v] += sz[u];
	sum[v] += sum[u];
	if(good){
		if(d[v].size() < d[u].size()) swap(d[u], d[v]);
		for(int x : d[u]) d[v].push_back(x);
	}
}

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

	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		cin >> s[i];
		v.push_back({s[i], i});
		uf[i] = -1; sz[i] = 1;
		d[i] = {i};
		sum[i] = s[i];
	}
	for(int i = 0; i < m; ++i){
		int u, v;
		cin >> u >> v, --u, --v;
		adj[u].push_back(v); adj[v].push_back(u);
	}
	sort(v.begin(), v.end());
	for(pair<int, int> p : v){
		for(int x : adj[p.second]){
			if(bio[x]){
				int root = f(x);
				join(root, f(p.second), sum[root] >= s[p.second]);
			}
		}
		bio[p.second] = 1;
	}
	for(int i = 0; i < n; ++i) ans[i] = 0;

	int source = f(v.back().second);
	for(int x : d[source]) ans[x] = 1;
	for(int i = 0; i < n; ++i) cout << ans[i];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9732 KB Output is correct
3 Correct 4 ms 9740 KB Output is correct
4 Correct 5 ms 9920 KB Output is correct
5 Correct 5 ms 9940 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 6 ms 9896 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 5 ms 9940 KB Output is correct
10 Correct 7 ms 9940 KB Output is correct
11 Correct 8 ms 9940 KB Output is correct
12 Correct 5 ms 9940 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 107 ms 29800 KB Output is correct
4 Correct 107 ms 33080 KB Output is correct
5 Correct 115 ms 35188 KB Output is correct
6 Correct 120 ms 36040 KB Output is correct
7 Correct 129 ms 36060 KB Output is correct
8 Correct 106 ms 34532 KB Output is correct
9 Correct 113 ms 37136 KB Output is correct
10 Correct 90 ms 32620 KB Output is correct
11 Correct 118 ms 34268 KB Output is correct
12 Correct 110 ms 32540 KB Output is correct
13 Correct 137 ms 32992 KB Output is correct
14 Correct 99 ms 33092 KB Output is correct
15 Correct 99 ms 34460 KB Output is correct
16 Correct 83 ms 33628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9664 KB Output is correct
2 Correct 179 ms 32268 KB Output is correct
3 Correct 145 ms 32332 KB Output is correct
4 Correct 127 ms 34496 KB Output is correct
5 Correct 97 ms 32696 KB Output is correct
6 Correct 153 ms 36600 KB Output is correct
7 Correct 117 ms 34488 KB Output is correct
8 Correct 114 ms 34568 KB Output is correct
9 Correct 75 ms 33616 KB Output is correct
10 Correct 107 ms 32960 KB Output is correct
11 Correct 135 ms 32636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 148 ms 30068 KB Output is correct
3 Correct 156 ms 34840 KB Output is correct
4 Correct 152 ms 36080 KB Output is correct
5 Correct 147 ms 37256 KB Output is correct
6 Correct 176 ms 34572 KB Output is correct
7 Correct 119 ms 35236 KB Output is correct
8 Correct 90 ms 32824 KB Output is correct
9 Correct 92 ms 23392 KB Output is correct
10 Correct 124 ms 36568 KB Output is correct
11 Correct 128 ms 32660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 4 ms 9732 KB Output is correct
3 Correct 4 ms 9740 KB Output is correct
4 Correct 5 ms 9920 KB Output is correct
5 Correct 5 ms 9940 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 6 ms 9896 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 5 ms 9940 KB Output is correct
10 Correct 7 ms 9940 KB Output is correct
11 Correct 8 ms 9940 KB Output is correct
12 Correct 5 ms 9940 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9940 KB Output is correct
15 Correct 4 ms 9684 KB Output is correct
16 Correct 4 ms 9684 KB Output is correct
17 Correct 107 ms 29800 KB Output is correct
18 Correct 107 ms 33080 KB Output is correct
19 Correct 115 ms 35188 KB Output is correct
20 Correct 120 ms 36040 KB Output is correct
21 Correct 129 ms 36060 KB Output is correct
22 Correct 106 ms 34532 KB Output is correct
23 Correct 113 ms 37136 KB Output is correct
24 Correct 90 ms 32620 KB Output is correct
25 Correct 118 ms 34268 KB Output is correct
26 Correct 110 ms 32540 KB Output is correct
27 Correct 137 ms 32992 KB Output is correct
28 Correct 99 ms 33092 KB Output is correct
29 Correct 99 ms 34460 KB Output is correct
30 Correct 83 ms 33628 KB Output is correct
31 Correct 6 ms 9664 KB Output is correct
32 Correct 179 ms 32268 KB Output is correct
33 Correct 145 ms 32332 KB Output is correct
34 Correct 127 ms 34496 KB Output is correct
35 Correct 97 ms 32696 KB Output is correct
36 Correct 153 ms 36600 KB Output is correct
37 Correct 117 ms 34488 KB Output is correct
38 Correct 114 ms 34568 KB Output is correct
39 Correct 75 ms 33616 KB Output is correct
40 Correct 107 ms 32960 KB Output is correct
41 Correct 135 ms 32636 KB Output is correct
42 Correct 4 ms 9684 KB Output is correct
43 Correct 148 ms 30068 KB Output is correct
44 Correct 156 ms 34840 KB Output is correct
45 Correct 152 ms 36080 KB Output is correct
46 Correct 147 ms 37256 KB Output is correct
47 Correct 176 ms 34572 KB Output is correct
48 Correct 119 ms 35236 KB Output is correct
49 Correct 90 ms 32824 KB Output is correct
50 Correct 92 ms 23392 KB Output is correct
51 Correct 124 ms 36568 KB Output is correct
52 Correct 128 ms 32660 KB Output is correct
53 Correct 4 ms 9724 KB Output is correct
54 Correct 4 ms 9684 KB Output is correct
55 Correct 4 ms 9684 KB Output is correct
56 Correct 5 ms 9864 KB Output is correct
57 Correct 5 ms 9864 KB Output is correct
58 Correct 5 ms 9868 KB Output is correct
59 Correct 5 ms 9864 KB Output is correct
60 Correct 5 ms 9812 KB Output is correct
61 Correct 5 ms 9940 KB Output is correct
62 Correct 5 ms 9960 KB Output is correct
63 Correct 5 ms 9940 KB Output is correct
64 Correct 5 ms 9940 KB Output is correct
65 Correct 5 ms 9940 KB Output is correct
66 Correct 6 ms 9940 KB Output is correct
67 Correct 107 ms 34320 KB Output is correct
68 Correct 130 ms 33132 KB Output is correct
69 Correct 137 ms 35160 KB Output is correct
70 Correct 118 ms 35936 KB Output is correct
71 Correct 124 ms 36024 KB Output is correct
72 Correct 117 ms 34556 KB Output is correct
73 Correct 114 ms 37048 KB Output is correct
74 Correct 91 ms 32600 KB Output is correct
75 Correct 127 ms 34256 KB Output is correct
76 Correct 107 ms 32516 KB Output is correct
77 Correct 111 ms 33068 KB Output is correct
78 Correct 100 ms 33080 KB Output is correct
79 Correct 116 ms 34544 KB Output is correct
80 Correct 89 ms 33560 KB Output is correct
81 Correct 158 ms 36600 KB Output is correct
82 Correct 149 ms 36832 KB Output is correct
83 Correct 132 ms 34548 KB Output is correct
84 Correct 97 ms 32660 KB Output is correct
85 Correct 153 ms 36660 KB Output is correct
86 Correct 133 ms 34628 KB Output is correct
87 Correct 112 ms 34528 KB Output is correct
88 Correct 101 ms 32904 KB Output is correct
89 Correct 146 ms 32696 KB Output is correct
90 Correct 149 ms 34612 KB Output is correct
91 Correct 147 ms 34928 KB Output is correct
92 Correct 160 ms 36008 KB Output is correct
93 Correct 149 ms 37216 KB Output is correct
94 Correct 152 ms 34604 KB Output is correct
95 Correct 108 ms 35168 KB Output is correct
96 Correct 80 ms 32788 KB Output is correct
97 Correct 80 ms 23284 KB Output is correct
98 Correct 138 ms 36608 KB Output is correct
99 Correct 121 ms 32764 KB Output is correct
100 Correct 34 ms 14156 KB Output is correct
101 Correct 152 ms 35248 KB Output is correct
102 Correct 114 ms 30296 KB Output is correct
103 Correct 129 ms 30460 KB Output is correct
104 Correct 149 ms 33868 KB Output is correct