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 "werewolf.h"
#include "bits/stdc++.h"
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
const int INF = 1e9;
vvi adj;
void dfsHuman(int src, vector<bool> &reachable, int L)
{
if (src < L)
return;
reachable[src] = true;
for (int a : adj[src])
{
if (reachable[a])
continue;
dfsHuman(a, reachable, L);
}
}
void dfsWolf(int src, vector<bool> &reachable, int R)
{
if (src > R)
return;
reachable[src] = true;
for (int a : adj[src])
{
if (reachable[a])
continue;
dfsHuman(a, reachable, R);
}
}
vi check_validity(int N, vi X, vi Y, vi S, vi E, vi L, vi R)
{
adj = vvi(N);
for (int i = 0; i < N; i++)
{
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
int Q = S.size();
vi ans(Q, false);
for (int i = 0; i < Q; i++)
{
vector<bool> reachableHuman(N, false);
dfsHuman(S[i], reachableHuman, L[i]);
vector<bool> reachableWolf(N, false);
dfsWolf(E[i], reachableWolf, R[i]);
for (int a = L[i]; a <= R[i]; a++)
ans[i] |= (reachableHuman[a] && reachableWolf[a]);
}
return ans;
}
# | 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... |