이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
const int MAX=1e9;
const int MAX_N=1e5;
vector<vi> G;
bool vis[MAX_N];
vector<vi> ll;
int pa[MAX_N],tam[MAX_N];
void init(int n){
for(int i=0;i<n;i++){
pa[i]=i; tam[i]=1;
}
}
int findset(int i){
if(pa[i]==i) return i;
return pa[i]=findset(pa[i]);
}
bool issameset(int i,int j){
return findset(i)==findset(j);
}
void unionset(int i,int j){
if(!issameset(i,j)){
int u=findset(i),v=findset(j);
pa[u]=v;
tam[v]+=tam[u];
}
}
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) {
int n=r.size(); int m=u.size();
ll.resize(n+1);
for(int i=0;i<m;i++){
ll[c[i]].push_back(i);
}
vector<int> ans(n,0);
int mi=MAX;
for(int i=0;i<n;i++){
init(n);
memset(vis,0,sizeof vis);
queue<int> q;
q.push(r[i]);
while(!q.empty()){
int x=q.front();
vis[x]=1;
q.pop();
for(int j=0;j<ll[x].size();j++){
int a=u[ll[x][j]],b=v[ll[x][j]];
unionset(a,b);
}
if(mi<tam[findset(i)]) break;
for(int j=0;j<n;j++){
if(!vis[r[j]] && issameset(i,j)){
q.push(r[j]);
}
}
}
if(mi>tam[findset(i)]){
for(int j=0;j<n;j++) ans[j]=0;
mi=tam[findset(i)];
}
if(mi==tam[findset(i)]){
ans[i]=1;
}
//cout<<tam[findset(i)]<<endl;
}
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:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int j=0;j<ll[x].size();j++){
| ~^~~~~~~~~~~~~
# | 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... |