Submission #796749

# Submission time Handle Problem Language Result Execution time Memory
796749 2023-07-28T16:53:57 Z ToniB Stranded Far From Home (BOI22_island) C++17
10 / 100
446 ms 524288 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);
	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 9684 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 7 ms 11604 KB Output is correct
5 Correct 6 ms 10324 KB Output is correct
6 Correct 9 ms 13140 KB Output is correct
7 Correct 7 ms 11604 KB Output is correct
8 Correct 7 ms 11480 KB Output is correct
9 Correct 12 ms 15108 KB Output is correct
10 Correct 5 ms 9948 KB Output is correct
11 Correct 5 ms 9940 KB Output is correct
12 Correct 5 ms 9884 KB Output is correct
13 Correct 14 ms 20104 KB Output is correct
14 Correct 6 ms 10068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9616 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Runtime error 420 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 164 ms 40188 KB Output is correct
3 Correct 166 ms 45236 KB Output is correct
4 Runtime error 362 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Runtime error 446 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 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 5 ms 9680 KB Output is correct
4 Correct 7 ms 11604 KB Output is correct
5 Correct 6 ms 10324 KB Output is correct
6 Correct 9 ms 13140 KB Output is correct
7 Correct 7 ms 11604 KB Output is correct
8 Correct 7 ms 11480 KB Output is correct
9 Correct 12 ms 15108 KB Output is correct
10 Correct 5 ms 9948 KB Output is correct
11 Correct 5 ms 9940 KB Output is correct
12 Correct 5 ms 9884 KB Output is correct
13 Correct 14 ms 20104 KB Output is correct
14 Correct 6 ms 10068 KB Output is correct
15 Correct 4 ms 9616 KB Output is correct
16 Correct 4 ms 9684 KB Output is correct
17 Runtime error 420 ms 524288 KB Execution killed with signal 9
18 Halted 0 ms 0 KB -