# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
139154 | rajarshi_basu | Werewolf (IOI18_werewolf) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "combo.h"
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i = a;i<=b;i++)
#define ll long long int
#define pb push_back
#define vi vector<int>
#define ff first
#define ss second
#define vv vector
#define ii pair<int,int>
using namespace std;
const int MAXN = 3001;
vi g[MAXN];
bool reachableHuman[MAXN];
bool reachableWolf[MAXN];
bool vis[MAXN];
int dfs(int node,int mode,int x){
if(vis[node])return;
if(mode == 1)reachableHuman[node] = 1;
if(mode == 2)reachableWolf[node] = 1;
for(auto e : g[node]){
if(mode == 1 and e >= x)dfs(e,mode,x);
if(mode == 2 and e <= x)dfs(e,mode,x);
}
}
bool solve(int n,int l,int r,int s,int e){
FOR(i,n)reachableHuman[i] = reachableWolf[i] = vis[i] = 0;
dfs(s,1,l);
dfs(e,2,r);
FOR(i,n)if(reachableHuman[i] and reachableWolf[i])return true;
return false;
}
vi check_validity(int n,vi x,vi y,vi s,vi e,vi l,vi r){
FOR(i,x.size()){
g[x[i]].pb(y[i]);
g[y[i]].pb(x[i]);
}
int q = s.size();
vi ret;FOR(i,n)ret.pb(0);
FOR(i,q){
ret[i] = solve(n,l[i],r[i],s[i],e[i]);
}
return ret;
}
int ma1in(){
ios_base::sync_with_stdio(0);
cin.tie(0);
return 0;
}