#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define sp <<" "<<
#define endl "\n"
// as human, we can only reach other nodes such that the next node is either:
// - less than the current node
// - below Ri
// as wolf:
// - greater than the current node
// - above Li
// so every time in a path and we go leq or greq
// we can find bounds L R that allow this edge.
// generalize: there are edges that only certain bounds can take
// how do we query these edges and connectivity quickly?
// instead phrase it from one side
// only consider human
// process in increasing Ri
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
int Q = S.size(), M = X.size();
vector<int> ans(Q);
vector<vector<int>> adj(N);
for (int i = 0; i < M; i++) {
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
for (int i = 0; i < Q; i++) {
if (S[i] < L[i] or E[i] > R[i]) {
ans[i] = 0;
continue;
}
// bfs
vector<int> bs;
vector<bool> vis;
vis.assign(N, false);
queue<int> q;
vis[S[i]] = true;
q.emplace(S[i]);
while (!q.empty()) {
auto u = q.front(); q.pop();
for (auto &v : adj[u]) {
if (!vis[v] and v >= L[i]) {
vis[v] = true;
q.emplace(v);
if (L[i] <= v and v <= R[i]) {
bs.emplace_back(v);
}
}
}
}
vis.assign(N, false);
for (auto &v : bs) {
vis[v] = true;
q.emplace(v);
}
while (!q.empty()) {
auto u = q.front(); q.pop();
for (auto &v : adj[u]) {
if (!vis[v] and v <= R[i]) {
vis[v] = true;
q.emplace(v);
}
}
}
// for (int i = 0; i < N; i++) {
// cerr << vis[i] << " ";
// } cerr << endl;
ans[i] = vis[E[i]];
}
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... |