Submission #600461

#TimeUsernameProblemLanguageResultExecution timeMemory
6004612fat2codeKeys (IOI21_keys)C++17
0 / 100
10 ms14512 KiB
#include <bits/stdc++.h> #define fr first #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define sc second #define all(s) s.begin(), s.end() #define rc(s) return cout << s, 0 using namespace std; const int nmax = 300005; int n, m, par[nmax], kek[nmax]; bitset<nmax>viz, keys, lol; vector<pair<int,int>>nod[nmax]; vector<int>waiting[nmax]; vector<pair<int,int>>change; vector<int>lmao; int findpar(int x){ if(par[x] != x){ par[x] = findpar(par[x]); } return par[x]; } void bfs(int s, vector<int>&type){ keys.reset(); viz.reset(); queue<int>q; q.push(s); lmao.push_back(s); viz[s] = 1; vector<int>zb; while(q.size()){ auto it = q.front(); keys[type[it-1]] = 1; q.pop(); for(auto it : waiting[type[it-1]]){ if(findpar(it) != s){ change.push_back({s, findpar(it)}); break; } if(!viz[it]){ q.push(it); lmao.push_back(it); viz[it] = 1; } } waiting[type[it-1]].clear(); for(auto it : nod[s]){ if(findpar(it.fr) != s && keys[it.sc]){ change.push_back({s, par[it.fr]}); break; } if(keys[it.sc] && !viz[it.fr]){ q.push(it.fr); viz[it.fr] = 1; lmao.push_back(it.fr); } else if(!keys[it.sc]){ waiting[it.sc].push_back(it.fr); zb.push_back(it.sc); } } } for(auto it : zb) waiting[it].clear(); } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { n = r.size(); vector<int>ans(n); m = u.size(); for(int i=0;i<m;i++){ nod[u[i]+1].push_back({v[i]+1, c[i]}); nod[v[i]+1].push_back({u[i]+1, c[i]}); } for(int i=1;i<=n;i++) par[i] = i; while(true){ lol.reset(); change.clear(); vector<int>roots; for(int i=1;i<=n;i++){ if(par[i] == i){ roots.push_back(i); } } for(auto it : roots){ bfs(it, r); } if(!change.size()) break; else{ for(auto it : change){ if(!lol[it.fr]){ par[it.fr] = it.sc; lol[it.sc] = 1; } } } } for(int i=1;i<=n;i++){ if(par[i] == i){ lmao.clear(); bfs(i, r); int xd = lmao.size(); for(auto it : lmao) kek[it] = xd; } } int maxi = 1e18; for(int i=1;i<=n;i++){ if(kek[i] && maxi > kek[i]) maxi = kek[i]; } for(int i=1;i<=n;i++){ if(maxi == kek[i]) ans[i - 1] = 1; } return ans; }

Compilation message (stderr)

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:108:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
  108 |     int maxi = 1e18;
      |                ^~~~
#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...