# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
657524 | abcvuitunggio | Werewolf (IOI18_werewolf) | C++17 | 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 <iostream>
#include <bitset>
#include <vector>
#include <queue>
using namespace std;
int n,m,q,u,v,s,e,l,r;
vector <int> ke[200001];
bitset <500001> d;
int bfs(){
d.reset();
d[s*2+1]=d[e*2]=1;
queue <int> q;
q.push(s);
q.push(e);
while (!q.empty()){
int u=q.front();
q.pop();
int x=d[u*2]*2+d[u*2+1];
if (x==3)
return 1;
for (int v:ke[u]){
int y=d[v*2]*2+d[v*2+1],z=(v<=r)*2+(v>=l);
if (((x|y)!=y)&&((x&z)==x)){
d[v*2+1]=(x&1)|(y&1);
d[v*2]=(x>>1)|(y>>1);
q.push(v);
}
}
}
return 0;
}
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> m >> q;
for (int i=1;i<=m;i++){
cin >> u >> v;
ke[u].push_back(v);
ke[v].push_back(u);
}
while (q--){
cin >> s >> e >> l >> r;
cout << bfs() << '\n';
}
}