Submission #973922

#TimeUsernameProblemLanguageResultExecution timeMemory
973922c2zi6Stranded Far From Home (BOI22_island)C++14
10 / 100
1079 ms18504 KiB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n, m;
VI s;
VVI gp;

void solve() {
	cin >> n >> m;
	s = VI(n);
	for (int& x : s) cin >> x;
	gp = VVI(n);
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		gp[u].pb(v);
		gp[v].pb(u);
	}


	VI ans(n);
	rep(r, n) {
		VI vis(n);
		ll sum = s[r];
		vis[r] = true;
		priority_queue<PII> pq;
		for (int v : gp[r]) pq.push({-s[v], v});
		while (pq.size()) {
			int u = pq.top().ss;
			pq.pop();
			if (vis[u]) continue;
			/* cout << "VARAQVAV " << u+1 << endl; */
			/* cout << "SUM = " << sum << endl; */
			/* cout << "s[" << u+1 << "] = " << s[u] << endl; */
			if (sum >= s[u]) {
				sum += s[u];
				vis[u] = true;
				for (int v : gp[u]) if (!vis[v]) pq.push({-s[v], v});
			} else {
				break;
			}
		}
		bool kexni = true;
		rep(u, n) if (!vis[u]) kexni = false;
		ans[r] = kexni;
		/* if (kexni) cout << "YES" << endl; */
		/* else cout << "NO" << endl; */
	}

	for (int x : ans) cout << x; cout << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    /* cin >> t; */
    while (t--) solve();
}

Compilation message (stderr)

island.cpp: In function 'void solve()':
island.cpp:80:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   80 |  for (int x : ans) cout << x; cout << endl;
      |  ^~~
island.cpp:80:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   80 |  for (int x : ans) cout << x; cout << endl;
      |                               ^~~~
#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...