Submission #869445

#TimeUsernameProblemLanguageResultExecution timeMemory
869445lolismekStranded Far From Home (BOI22_island)C++14
0 / 100
2 ms6748 KiB
#include <algorithm> #include <iostream> #include <fstream> #include <vector> #include <queue> #define pii pair <int, int> using namespace std; //ifstream fin("input.in"); //ofstream fout("output.out"); #define fin cin #define fout cout const int NMAX = 2e5; int v[NMAX + 1]; vector <int> adj[NMAX + 1]; int par[NMAX + 1]; int sum[NMAX + 1]; int Find(int x){ if(x == par[x]){ return x; } return par[x] = Find(par[x]); } void Join(int x, int y){ x = par[x]; y = par[y]; par[x] = y; sum[y] += sum[x]; } bool ins[NMAX + 1]; void Insert(int x){ ins[x] = true; for(int vec : adj[x]){ if(ins[vec]){ Join(vec, x); } } } bool ans[NMAX + 1]; int main(){ int n, m; fin >> n >> m; vector <pii> aux; priority_queue <pii, vector <pii>, greater <pii>> pq; for(int i = 1; i <= n; i++){ fin >> v[i]; par[i] = i; sum[i] = v[i]; aux.push_back({v[i], i}); pq.push({v[i], i}); ans[i] = 1; } for(int i = 1; i <= m; i++){ int a, b; fin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } //cout << v[1] << ' ' << v[1010] << ' ' << v[1999] << ' ' << v[2000] << endl; sort(aux.begin(), aux.end()); for(int i = 0; i < (int)aux.size(); i++){ //cout << i << endl; int val = aux[i].first; Insert(aux[i].second); //cout << "-- " << aux[i].second << endl; while(i + 1 < (int)aux.size() && aux[i + 1].first == aux[i].first){ Insert(aux[++i].second); //cout << "-- " << aux[i].second << endl; } if(i == 1999){ //cout << ") " << (int)pq.size() << endl; } vector <pii> toinsert; while(!pq.empty() && ((i == (int)aux.size() - 1 && pq.top().first >= val) || (i < (int)aux.size() - 1 && pq.top().first >= val && pq.top().first < aux[i + 1].first))){ int node = pq.top().second; int x = pq.top().first; pq.pop(); int s = sum[Find(node)]; if(i == 1999){ // cout << ")) " << node << endl; } if(s == x){ // cout << ">> " << node << ' ' << val << ' ' << x << ' ' << s << endl; ans[node] = 0; }else{ toinsert.push_back({s, node}); } } for(pii x : toinsert){ if(i == (int)aux.size() - 1){ continue; } if(x.first >= aux[i + 1].first){ pq.push(x); }else{ ans[x.second] = 0; } } } for(int i = 1; i <= n; i++){ fout << ans[i]; } fout << '\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...