Submission #727064

# Submission time Handle Problem Language Result Execution time Memory
727064 2023-04-20T02:20:26 Z NeroZein Stranded Far From Home (BOI22_island) C++17
0 / 100
93 ms 31636 KB
#include <bits/stdc++.h>
using namespace std;

struct edge {
	int u, v, val;
	bool operator <(const edge& y) {
		return val < y.val; 
	}
};

const int N = 200005;

int rt;
int a[N];
edge e[N]; 
bool can[N];
vector<int> g[N]; 

int p[N], sz[N];

int get (int v) {
	return p[v] = (p[v] == v ? v : get(p[v]));
}

void uni (int u, int v) {
	int pu = get(u), pv = get(v);
	if (pu == pv) return; 
	rt++;
	p[rt] = p[u] = p[v] = rt;
	//cout << " ps: " << pu << ' ' << pv << '\n';
	a[rt] = a[pu] + a[pv];
	//cout << " as : " << a[pu] << ' ' << a[pv] << '\n';
	if (a[u] <= a[pv]) {
		//cout << " u : " << u << ' ' << v << '\n';
		g[rt].push_back(pv);
	}
	if (a[v] <= a[pu]) {
		//cout << " v : " << v << ' ' << u << '\n'; 
		g[rt].push_back(pu); 
	}
	//cout << '\n';
}

void Dfs (int v) {
	if (g[v].empty()) {
		can[v] = true; 
	}
	for (int u : g[v]) {
		Dfs(u); 
	}
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		p[i] = i;
		sz[i] = 1;
	}
	for (int i = 0; i < m; ++i) {
		cin >> e[i].u >> e[i].v;
		e[i].val = max(a[e[i].u], a[e[i].v]);
	}
	sort(e, e + m); 
	rt = n;
	for (int i = 0; i < m; ++i) {
		//cout << " e: " << e[i].u << ' ' << e[i].v << '\n';
		uni(e[i].u, e[i].v); 
	}
	Dfs(rt); 
	for (int i = 1; i <= n; ++i) {
		cout << can[i];
	}
	cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Incorrect 3 ms 5168 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Runtime error 93 ms 31636 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Runtime error 92 ms 23972 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5028 KB Output is correct
2 Runtime error 71 ms 23940 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Incorrect 3 ms 5168 KB Output isn't correct
5 Halted 0 ms 0 KB -