Submission #1078889

#TimeUsernameProblemLanguageResultExecution timeMemory
1078889hcngStranded Far From Home (BOI22_island)C++14
100 / 100
102 ms29612 KiB
#include <bits/stdc++.h> using namespace std; #define int long long char *p1, *p2, buf[1<<20]; #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++) inline int read() {int x=0;char c=gc();while(!isdigit(c))c=gc();while(isdigit(c))x=x*10+c-'0',c=gc();return x;} #define pc(c) putchar(c) void write(int x) {if(x>9)write(x/10);pc('0'+x%10);} int n, m; int a[200010], b[200010]; vector<int> G[200010]; int dsu[200010], tag[200010], sum[200010]; int ans[200010], vis[200010]; int find(int u) { int r = (u == dsu[u]? u : find(dsu[u])); tag[u] |= tag[dsu[u]]; if (tag[u]) ans[u] = 0; dsu[u] = r; return r; } signed main() { n = read(), m = read(); for (int i = 1; i <= n; i++) { a[i] = read(); dsu[i] = b[i] = i; } for (int i = 1; i <= m; i++) { int u = read(), v = read(); G[u].push_back(v); G[v].push_back(u); } sort(b + 1, b + 1 + n, [](int x, int y){return a[x]<a[y];}); for (int i = 1; i <= n; i++) { int u = b[i]; ans[u] = vis[u] = 1; sum[u] = a[u]; for (int v : G[u]) { if (!vis[v]) continue; v = find(v); if (v == u) continue; if (sum[v] < a[u]) tag[v] = 1; dsu[v] = u; sum[u] += sum[v]; } } for (int i = 1; i <= n; i++) { find(i); } for (int i = 1; i <= n; i++) { write(ans[i]); } pc('\n'); return 0; }
#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...