Submission #744917

#TimeUsernameProblemLanguageResultExecution timeMemory
744917josanneo22Stranded Far From Home (BOI22_island)C++17
0 / 100
1081 ms17384 KiB
#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
using namespace std;

#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second 
const int maxn = 2e5 + 50;
vector<vector<int>> adj(maxn);
vector<int>vis(maxn), s(maxn);
int tot;
void run(int u) {
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	pq.push(mp(0, u));
	while (pq.size()) {
		pii uu = pq.top(); pq.pop();
		if (vis[uu.se] || uu.fi > tot) continue; 
		vis[uu.se] = 1; tot += uu.fi;
		for (auto& v : adj[uu.se]) {
			pq.push(mp(s[v], v));
		}
	}
}
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> s[i];
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) vis[j] = 0;
		tot = s[i]; run(i);
		int ok = 1; for (int j = 0; j < n; j++) ok &= vis[j];
		cout << ok;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...