Submission #796682

# Submission time Handle Problem Language Result Execution time Memory
796682 2023-07-28T15:39:04 Z ToniB Stranded Far From Home (BOI22_island) C++17
0 / 100
139 ms 33472 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){
	if(u == v) return ;
	if(sz[u] > sz[v]) swap(u, v);
	uf[u] = v;
	sz[v] += sz[u];
	sum[v] += sum[u];
	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);
				if(sum[root] >= s[p.second]){
					join(root, f(p.second));
				}
			}
		}
		bio[p.second] = 1;
	}
	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 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Incorrect 5 ms 9832 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9724 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Incorrect 118 ms 33472 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 119 ms 32428 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Incorrect 139 ms 32608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9720 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Incorrect 5 ms 9832 KB Output isn't correct
5 Halted 0 ms 0 KB -