Submission #868057

# Submission time Handle Problem Language Result Execution time Memory
868057 2023-10-30T10:36:57 Z TAhmed33 Stranded Far From Home (BOI22_island) C++
0 / 100
357 ms 61012 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2e5 + 25;
vector <int> adj2[MAXN];
vector <int> adj[MAXN];
bool ok[MAXN];
set <int> pp;
int cnt[MAXN];
bool vis[MAXN];
int sum = 0;
vector <int> cur;
int y;
void dfs (int pos) {
	vis[pos] = 1; sum += cnt[pos]; cur.push_back(pos);
	for (auto j : adj[pos]) if (!vis[j] && cnt[j] <= y) dfs(j);
}
signed main () {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> cnt[i];
		pp.insert(cnt[i]);
	}
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		adj2[a].push_back(b);
		adj2[b].push_back(a);
	}
	for (int i = 1; i <= n; i++) ok[i] = 1;
	int z = pp.size();
	for (int l = 0; l + 1 < z; l++) {
		auto i = *(pp.begin()); pp.erase(i); y = i;
		for (int j = 1; j <= n; j++) {
			for (auto k : adj2[j]) {
				if (cnt[j] == i || cnt[k] == i) {
					adj[i].push_back(j);
					adj[j].push_back(i);
				}
			}
		}
		memset(vis, 0, sizeof(vis));
		for (int j = 1; j <= n; j++) {
			if (!vis[j] && cnt[j] <= y) {
				sum = 0; cur.clear();
				dfs(j);
				if (sum < *(pp.begin())) {
					for (auto l : cur) {
						ok[l] = 0;
					}
				}
			}
		}
	}	
	for (int i = 1; i <= n; i++) cout << ok[i];
	cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11612 KB Output is correct
2 Correct 2 ms 11612 KB Output is correct
3 Correct 2 ms 11608 KB Output is correct
4 Runtime error 13 ms 23900 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11612 KB Output is correct
2 Correct 2 ms 11608 KB Output is correct
3 Runtime error 357 ms 61012 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11608 KB Output is correct
2 Runtime error 307 ms 58944 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11868 KB Output is correct
2 Runtime error 202 ms 42204 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11612 KB Output is correct
2 Correct 2 ms 11612 KB Output is correct
3 Correct 2 ms 11608 KB Output is correct
4 Runtime error 13 ms 23900 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -