Submission #646778

#TimeUsernameProblemLanguageResultExecution timeMemory
646778Tenis0206Stranded Far From Home (BOI22_island)C++11
0 / 100
282 ms43528 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n,m; int s[200005]; vector<int> G[200005]; bool ok[200005]; int t[200005],sum[200005]; vector<int> l[200005]; int p[200005]; int reprezentant(int nod) { if(t[nod]==nod) { return t[nod]; } return t[nod] = reprezentant(t[nod]); } void uneste(int x, int y) { x = reprezentant(x); y = reprezentant(y); if(x==y) { return; } if(l[x].size() > l[y].size()) { t[y] = x; sum[x] += sum[y]; for(auto it : l[y]) { l[x].push_back(it); } } else { t[x] = y; sum[y] += sum[x]; for(auto it : l[x]) { l[y].push_back(it); } } } bool cmp(int a, int b) { return s[a] < s[b]; } signed main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef home freopen("nr.in","r",stdin); freopen("nr.out","w",stdout); #endif // home cin>>n>>m; for(int i=1; i<=n; i++) { cin>>s[i]; p[i] = i; } for(int i=1; i<=m; i++) { int x,y; cin>>x>>y; if(x==3 || y==3) { x = 3; } G[x].push_back(y); G[y].push_back(x); } for(int i=1; i<=n; i++) { t[i] = i; l[i].push_back(i); sum[i] = s[i]; ok[i] = true; } sort(p+1,p+n+1,cmp); for(int i=1;i<=n;i++) { int nod = p[i]; for(auto it : G[nod]) { if(s[it] > s[nod]) { continue; } if(it==965) { s[it] = s[it] - 1 + 1 ; } if(sum[reprezentant(it)] >= s[nod]) { uneste(nod,it); } else { for(auto e : l[reprezentant(it)]) { ok[e] = false; } uneste(nod,it); } } } for(int i=1; i<=n; i++) { cout<<ok[i]; } 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...