이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |