#include<bits/stdc++.h>
using namespace std;
#include "werewolf.h"
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"
using ll = long long;
using ld = long double;
template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}
const int N = 2e5 + 5;
int n, m, q, dsu[N], tin[N], tout[N], timerDFS;
vector<int> Edge[N], tree[N]; set<int> sub[N]; vector<int> Q[N];
int asc(int x){
return dsu[x] == x ? x : dsu[x] = asc(dsu[x]);
}
bool inSub(int u, int v){
return tin[u] <= tin[v] && tout[v] <= tout[u];
}
void unite(int u, int v){
u = asc(u), v = asc(v); // u is par
if(u != v){
// merge st v -> u
dsu[v] = u;
if(sz(sub[u]) < sz(sub[v]))
swap(sub[u], sub[v]);
for(int x : sub[v]) sub[u].insert(x);
}
}
void dfs1(int x, int p){
tin[x] = ++timerDFS;
for(int v : tree[x])if(v != p){
dfs1(v, x);
}
tout[x] = ++timerDFS;
}
vector<int> check_validity(int _n, vector<int> X, vector<int> Y,
vector<int> S, vector<int> E, vector<int> L, vector<int> R){
n = _n, m = sz(X), q = sz(E);
FOR(i, 0, m - 1) Edge[X[i]].eb(Y[i]), Edge[Y[i]].eb(X[i]);
FOR(i, 0, n - 1) dsu[i] = i;
FOR(x, 0, n - 1){
for(int v : Edge[x]){
if(v >= x) continue;
auto join = [&](int u, int v) -> void{ // u > v
u = asc(u), v = asc(v);
if(u != v){
dsu[v] = u;
tree[u].eb(v);
}
};
join(x, v);
}
}
dfs1(n - 1, -1);
FOR(i, 0, n - 1){
dsu[i] = i;
sub[i].insert(tin[i]);
}
vector<int> ans(q);
FOR(i, 0, q - 1) Q[L[i]].eb(i);
ROF(x, n - 1, 0){
for(int v : Edge[x]){
if(v <= x) continue;
unite(x, v);
}
for(int id : Q[x]){
if(!inSub(R[id], E[id])){
ans[id] = 0;
}
else{
if(sub[x].find(tin[S[id]]) != sub[x].end()){
sub[x].erase(tin[S[id]]);
auto it = sub[x].upper_bound(tin[R[id]]);
if(it != sub[x].end() && *it < tout[R[id]]){
ans[id] = 1;
}
else ans[id] = 0;
sub[x].insert(tin[S[id]]);
}
else{
ans[id] = 0;
}
}
}
}
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... |