이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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(it != s && par[it] == it){
change.push_back({s, 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(it.fr != s && par[it.fr] == it.fr && keys[it.sc]){
change.push_back({s, 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;
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |