이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "werewolf.h"
typedef vector<int> Vec;
const int maxN=400100;
Vec G[maxN];
int Fp[maxN],Fw[maxN],vis1[maxN],vis2[maxN],a[maxN];
int find1(int x){return x==Fp[x]?x:Fp[x]=find1(Fp[x]);}
int find2(int x){return x==Fw[x]?x:Fw[x]=find2(Fw[x]);}
void uni1(int x,int y){
int Fx=find1(x),Fy=find1(y);
if(Fx==Fy)return;
Fp[Fx]=Fy;
}
void uni2(int x,int y){
int Fx=find2(x),Fy=find2(y);
if(Fx==Fy)return;
Fw[Fx]=Fy;
}
void dfs1(int x,int l){
for (int i=0;i<a[x];i++)
if (!vis1[G[x][i]]&&G[x][i]>=l){
vis1[G[x][i]]=1;
dfs1(G[x][i],l);
}
}
bool dfs2(int x,int l,int r){
for (int i=0;i<a[x];i++)
if (!vis2[G[x][i]]&&G[x][i]<=r){
vis2[G[x][i]]=1;
if (l<=G[x][i]&&G[x][i]<=r)return 1;
else return dfs2(G[x][i],l,r);
}
}
Vec check_validity(int N,Vec X,Vec Y,Vec S,Vec E,Vec L,Vec R) {
int M=X.size(),Q=S.size();
Vec A;
A.clear();
if(M==N-1){
for (int q=0;q<Q;q++){
memset(a,0,sizeof(a));
memset(vis1,0,sizeof(vis1));
memset(vis2,0,sizeof(vis2));
for (int i=0;i<M;i++){
G[X[i]].push_back(Y[i]);
G[Y[i]].push_back(X[i]);
a[X[i]]++;a[Y[i]]++;
}
dfs1(S[q],L[q]);//people
if(dfs2(E[q],L[q],R[q]))A.push_back(1);//werewolf
else A.push_back(0);
}
}else{
for (int q=0;q<Q;q++){
for (int i=0;i<N;i++)Fp[i]=i,Fw[i]=i;
for (int i=0;i<M;i++){
if (X[i]>=L[q]&&Y[i]>=L[q])uni1(X[i],Y[i]);
if (X[i]<=R[q]&&Y[i]<=R[q])uni2(X[i],Y[i]);
}
int no=1;
for (int i=L[q];i<=R[q];i++)
if (find1(Fp[S[q]])==find1(Fp[i])&&find2(Fw[E[q]])==find2(Fw[i])){
no=0;A.push_back(1);break;
}
if(no)A.push_back(0);
}
}
return A;
}
컴파일 시 표준 에러 (stderr) 메시지
werewolf.cpp: In function 'bool dfs2(int, int, int)':
werewolf.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |