이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
struct DSU {
vector<int>parent,sz;
void build(int n){
parent.resize(n);
sz.resize(n);
for (int i = 0;i<n;++i){
parent[i] = i;
sz[i] = 1;
}
}
int findsets(int v){
if (v == parent[v])return v;
parent[v] = findsets(parent[v]);
return parent[v];
}
bool unionset(int u,int v){
u = findsets(u);
v = findsets(v);
if (u == v)return false;
if (sz[u] < sz[v])swap(u,v);
sz[u]+=sz[v];
parent[v] = u;
return true;
}
};
/*
6 6 3
1 5
1 2
1 3
3 4
0 3
2 5
4 2 1 2
4 2 2 2
5 4 3 4
*/
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 q = (int)S.size();
vector<int>ans(q,0);
int m = (int)X.size();
vector<pair<int,int>>edges;
for (int i = 0;i<m;++i){
if (X[i] > Y[i])swap(X[i],Y[i]);
edges.push_back({X[i],Y[i]});
}
sort(edges.begin(),edges.end());
for (int i = 0;i<q;++i){
DSU human,wolf;
human.build(N);
wolf.build(N);
for (auto x:edges){
if (x.first >=L[i] && x.second>=L[i]){
//cout<<"human"<<" "<<x.first<<" "<<x.second<<'\n';
human.unionset(x.first,x.second);
}
if (x.first <=R[i] && x.second<=R[i]){
// cout<<"wolf"<<" "<<x.first<<" "<<x.second<<'\n';
wolf.unionset(x.first,x.second);
}
}
//cout<<'\n';
if (S[i] < L[i])ans[i] = 0;
else if (E[i] > R[i])ans[i] = 0;
else{
for (int j = L[i];j<=R[i];++j){
if (human.findsets(j) == human.findsets(S[i]) && wolf.findsets(j) == wolf.findsets(E[i])){
//cout<<i<<" "<<j<<'\n';
ans[i] = 1;
break;
}
}
}
}
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... |