Submission #714729

#TimeUsernameProblemLanguageResultExecution timeMemory
714729fuad27Stranded Far From Home (BOI22_island)C++17
0 / 100
874 ms49808 KiB
#include<bits/stdc++.h> using namespace std; struct DSU { vector<int> e; vector<int> sum; DSU(int N) { e = vector<int>(N, -1); sum=vector<int>(N,0); } int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } bool same_set(int a, int b) { return get(a) == get(b); } int size(int x) { return -e[get(x)]; } bool unite(int x, int y) { x = get(x), y = get(y); if (x == y) return false; if (e[x] > e[y]) swap(x, y); sum[x]+=sum[y]; sum[y]=0; e[x] += e[y]; e[y] = x; return true; } }; const int N=200'010; int s[N]; vector<int> gg[N]; vector<int> g[N]; int main () { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; set<int> ss; map<int,int> cc; for(int i = 0;i<n;i++) { cin >> s[i]; ss.insert(s[i]); cc[s[i]]=1; } { int cnt=0; for(auto &i:cc) { i.second=cnt++; } } for(int i = 0;i<m;i++) { int a, b; cin >> a >> b; a--,b--; gg[a].push_back(b); gg[b].push_back(a); } vector<int> ns[n]; for(int i = 0;i<n;i++) { ns[cc[s[i]]].push_back(i); } DSU d(n); vector<int> par(n); iota(par.begin(),par.end(),0); vector<int> res(n,1); for(int i = 0;i<n;i++)d.sum[i]=s[i]; for(int i = 0;i<n;i++) { for(int at:ns[i]) { for(int to:gg[at]) { if(cc[s[to]]<=i) { d.unite(at,to); } } for(int to:gg[at]) { if(cc[s[to]]<=i and res[par[to]]) { par[to]=d.get(at); } } if(res[par[at]]) par[at]=d.get(at); } if(ns[i].size()) { auto it=ss.upper_bound(s[ns[i][0]]); if(it==ss.end())continue; for(int at:ns[i]) { int mn=1e9; for(int to:gg[at]) { if(cc[s[to]]>i) { mn=min(mn,s[to]); } } if(d.sum[d.get(at)]<(*it)){ res[par[at]]=0; } } } } for(int i = 0;i<n;i++) { cout << res[par[i]] << ""; } }
#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...