제출 #600484

#제출 시각아이디문제언어결과실행 시간메모리
6004842fat2code열쇠 (IOI21_keys)C++17
100 / 100
1962 ms61988 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; 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 it1 : waiting[type[it-1]]){ if(findpar(it1) != s){ change.push_back({s, par[it1]}); goto next; } if(!viz[it1]){ q.push(it1); lmao.push_back(it1); viz[it1] = 1; } } waiting[type[it-1]].clear(); for(auto it1 : nod[it]){ if(findpar(it1.fr) != s && keys[it1.sc]){ change.push_back({s, par[it1.fr]}); goto next; } if(keys[it1.sc] && !viz[it1.fr]){ q.push(it1.fr); viz[it1.fr] = 1; lmao.push_back(it1.fr); } else if(!keys[it1.sc]){ waiting[it1.sc].push_back(it1.fr); zb.push_back(it1.sc); } } } next:; 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){ 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(findpar(it.fr) != findpar(it.sc)){ par[it.fr] = it.sc; } } } } 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; }

컴파일 시 표준 에러 (stderr) 메시지

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