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>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include "werewolf.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 3011;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
int curp[maxn], par[maxn][maxn][2], lvl[maxn], tmp[maxn];
vector<int>g[maxn];
int findp(int x){
return curp[x] = (curp[x]==x?x:findp(curp[x]));
}
void merge(int x,int y){
x = findp(x), y = findp(y);
if(x==y)return;
if(lvl[x]<lvl[y])swap(x,y);
curp[y] = x;
if(lvl[x]==lvl[y])lvl[x]++;
}
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();
for(int i=0;i<sz(X);++i){
int u = X[i], v = Y[i];
g[u].pb(v), g[v].pb(u);
}
for(int i=1;i<=N;++i){
curp[i] = par[i][0][0] = par[i][N+1][1] = i, lvl[i] = 0;
}
for(int i=1;i<=N;++i){
for(auto v:g[i]){
if(v<i)merge(v,i);
}
for(int j=1;j<=N;++j)par[j][i][0] = findp(j);
}
for(int i=1;i<=N;++i)curp[i] = i, lvl[i] = 0;
for(int i=N;i>=1;--i){
for(auto v:g[i]){
if(v>i)merge(v,i);
}
for(int j=1;j<=N;++j)par[j][i][1] = findp(j);
}
vector<int>ans(Q);
for(int i=0;i<Q;++i){
for(int j=L[i];j<=R[i];++j){
ans[i] |= par[j][L[i]][1]==par[S[i]][L[i]][1]&&
par[j][R[i]][0]==par[E[i]][R[i]][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... |