Submission #971417

#TimeUsernameProblemLanguageResultExecution timeMemory
971417Nare_2007Stranded Far From Home (BOI22_island)C++17
10 / 100
215 ms5980 KiB
#include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <set> #include <map> #include <queue> #include <stack> #include <deque> #include <iomanip> #include <cstdio> #include <string> #define ll long long using namespace std; #define sort(a) sort(a.begin(), a.end()) #define reverse(a) reverse(a.begin(), a.end()) #define lli long long int vector<ll> g[2005]; void solve() { ll n, m; cin >> n >> m; vector<ll> a(n + 1); for (ll i = 1; i <= n; ++i) { cin >> a[i]; } for (ll i = 0; i < m; ++i) { ll x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } string s = ""; for (ll i = 1; i <= n; ++i) { priority_queue<pair<ll, ll>> q; vector<bool> vis(n + 1); ll cnt = 0; q.push({ -a[i], i }); vis[i] = 1; bool b = 1; while (!q.empty()) { pair<ll, ll> p = q.top(); q.pop(); if(cnt && cnt < abs(p.first)) { s += '0'; b = 0; break; } cnt += abs(p.first); for (auto x : g[p.second]) { if (!vis[x]) { q.push({ -a[x], x }); vis[x] = 1; } } } if (b) { s += '1'; } } cout << s << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; //cin >> t; while (t--) { solve(); } }
#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...