Submission #120140

#TimeUsernameProblemLanguageResultExecution timeMemory
120140BoxworldWerewolf (IOI18_werewolf)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include <cstdio> #include <cstdlib> #include <vector> using namespace std; //#include "werewolf.h" namespace { int read_int() { int x; if (scanf("%d", &x) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } return x; } } // namespace 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; } int main() { int N = read_int(); int M = read_int(); int Q = read_int(); std::vector<int> X(M), Y(M), S(Q), E(Q), L(Q), R(Q); for (int j = 0; j < M; ++j) { X[j] = read_int(); Y[j] = read_int(); } for (int i = 0; i < Q; ++i) { S[i] = read_int(); E[i] = read_int(); L[i] = read_int(); R[i] = read_int(); } std::vector<int> A = check_validity(N, X, Y, S, E, L, R); for (int i = 0; i < A.size(); ++i) { printf("%d\n", A[i]); } return 0; }

Compilation message (stderr)

werewolf.cpp: In function 'int main()':
werewolf.cpp:105:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < A.size(); ++i) {
                   ~~^~~~~~~~~~
werewolf.cpp: In function 'bool dfs2(int, int, int)':
werewolf.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
/tmp/cc4HsKg5.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccYSkJwV.o:werewolf.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status