# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209670 | TAISA_ | Seats (IOI18_seats) | C++14 | 0 ms | 0 KiB |
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;
struct UF{
vector<int> par,sz;
UF(int n){
par.resize(n);
sz.resize(n,1);
for(int i=0;i<n;i++)par[i]=i;
}
int find(int x){
if(par[x]==x)return par[x];
return par[x]=find(par[x]);
}
void unite(int u,int v){
u=find(u);v=find(v);
if(u==v)return;
if(sz[u]<sz[v])swap(u,v);
par[v]=u;
sz[u]+=sz[v];
}
bool same(int u,int v){
return find(u)==find(v);
}
};
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
std::vector<int> S, std::vector<int> E,
std::vector<int> L, std::vector<int> R) {
int n=N,m=X.size(),q=S.size();
vector<int> res(q);
for(int i=0;i<q;i++){
UF ua(n),ub(n);
for(int j=0;j<m;j++){
if(X[j]<=R[i]&&Y[j]<=R[i]){
ua.unite(X[j],Y[j]);
}
if(X[j]>=L[i]&&Y[j]>=L[i]){
ub.unite(X[j],Y[j]);
}
}
for(int j=0;j<n;j++){
if(ua.same(E[i],j)&&ub.same(j,S[i])){
res[i]=1;
}
}
}
return res;
}