#include "werewolf.h"
#include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
template <typename T>
using matrix = vector<vector<T>>;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const double EPS = 1e-7;
const int MOD = 1e9 + 7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const int MAXN = 1e6+1;
struct UnionFind{
vector<int> pai;
vector<set<int>> lista;
UnionFind(int n = 0){
pai = vector<int>(n);
lista = vector<set<int>>(n);
iota(all(pai),0);
for(int i = 0; i < n; i++)
lista[i].insert(i);
}
int find(int id){
if(pai[id] == id)
return id;
return pai[id] = find(pai[id]);
}
void onion(int a, int b){
a = find(a);
b = find(b);
if(a == b)
return;
if(lista[a].size() > lista[b].size())
swap(a,b);
pai[a] = b;
for(int i : lista[a])
lista[b].insert(i);
}
};
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 = S.size();
matrix<int> g(n);
for(int i = 0; i < X.size(); i++){
g[X[i]].push_back(Y[i]);
g[Y[i]].push_back(X[i]);
}
matrix<int>child(n);
vector<int> pai(n), dirpai(n);
iota(all(pai),0);
iota(all(dirpai),0);
auto find=[&](int id, auto f)->int{
if(pai[id] == id)
return id;
return pai[id] = f(pai[id],f);
};
auto onion =[&](int a, int b){
a = find(a,find), b = find(b,find);
if(a == b)
return;
if(a > b)
swap(a,b);
pai[b] = a;
dirpai[b] = a;
child[a].push_back(b);
};
for(int i = n-1; i >= 0; i--){
for(int j : g[i]){
if(j > i)
onion(i,j);
}
}
vector<int> tin(n);
vector<pii> range(n);
int timer = -1;
auto dfs =[&](int id, auto dfs)->void{
tin[id] = ++timer;
range[id].ff = timer;
range[id].ss = timer;
for(int i : child[id]){
dfs(i,dfs);
range[id].ss = range[i].ss;
}
};
dfs(0,dfs);
matrix<int> lift(20,vector<int>(n));
for(int i = 0; i < n; i++){
lift[0][i] = dirpai[i];
}
for(int i = 1; i < 20; i++){
for(int j = 0; j < n; j++){
lift[i][j] = lift[i-1][lift[i-1][j]];
}
}
auto getroot =[&](int id, int l){
for(int i = 19; i >= 0; i--)
if(lift[i][id] >= l)
id = lift[i][id];
return id;
};
matrix<int> queries(n);
for(int i = 0; i < Q; i++){
queries[R[i]].push_back(i);
}
UnionFind uf(n);
vector<int> resp(Q);
for(int i = 0; i < n; i++){
for(int j : g[i]){
if(j < i)
uf.onion(tin[i],tin[j]);
}
for(int q : queries[i]){
int root = getroot(S[q],L[q]);
int rep = uf.find(tin[E[q]]);
auto it = uf.lista[rep].lower_bound(tin[root]);
resp[q] = it!=uf.lista[rep].end()&& *it <= range[root].ss;
}
}
return resp;
}
Compilation message
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0; i < X.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
8 ms |
1748 KB |
Output is correct |
11 |
Correct |
6 ms |
1760 KB |
Output is correct |
12 |
Correct |
7 ms |
2004 KB |
Output is correct |
13 |
Correct |
5 ms |
1492 KB |
Output is correct |
14 |
Correct |
5 ms |
1492 KB |
Output is correct |
15 |
Correct |
7 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
875 ms |
134316 KB |
Output is correct |
2 |
Correct |
787 ms |
92408 KB |
Output is correct |
3 |
Correct |
742 ms |
97324 KB |
Output is correct |
4 |
Correct |
698 ms |
105564 KB |
Output is correct |
5 |
Correct |
725 ms |
106952 KB |
Output is correct |
6 |
Correct |
771 ms |
113160 KB |
Output is correct |
7 |
Correct |
796 ms |
134716 KB |
Output is correct |
8 |
Correct |
598 ms |
92452 KB |
Output is correct |
9 |
Correct |
535 ms |
97916 KB |
Output is correct |
10 |
Correct |
472 ms |
103400 KB |
Output is correct |
11 |
Correct |
490 ms |
104880 KB |
Output is correct |
12 |
Correct |
604 ms |
114664 KB |
Output is correct |
13 |
Correct |
754 ms |
97420 KB |
Output is correct |
14 |
Correct |
735 ms |
97564 KB |
Output is correct |
15 |
Correct |
695 ms |
97404 KB |
Output is correct |
16 |
Correct |
790 ms |
97524 KB |
Output is correct |
17 |
Correct |
787 ms |
133940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
8 ms |
1748 KB |
Output is correct |
11 |
Correct |
6 ms |
1760 KB |
Output is correct |
12 |
Correct |
7 ms |
2004 KB |
Output is correct |
13 |
Correct |
5 ms |
1492 KB |
Output is correct |
14 |
Correct |
5 ms |
1492 KB |
Output is correct |
15 |
Correct |
7 ms |
1748 KB |
Output is correct |
16 |
Correct |
875 ms |
134316 KB |
Output is correct |
17 |
Correct |
787 ms |
92408 KB |
Output is correct |
18 |
Correct |
742 ms |
97324 KB |
Output is correct |
19 |
Correct |
698 ms |
105564 KB |
Output is correct |
20 |
Correct |
725 ms |
106952 KB |
Output is correct |
21 |
Correct |
771 ms |
113160 KB |
Output is correct |
22 |
Correct |
796 ms |
134716 KB |
Output is correct |
23 |
Correct |
598 ms |
92452 KB |
Output is correct |
24 |
Correct |
535 ms |
97916 KB |
Output is correct |
25 |
Correct |
472 ms |
103400 KB |
Output is correct |
26 |
Correct |
490 ms |
104880 KB |
Output is correct |
27 |
Correct |
604 ms |
114664 KB |
Output is correct |
28 |
Correct |
754 ms |
97420 KB |
Output is correct |
29 |
Correct |
735 ms |
97564 KB |
Output is correct |
30 |
Correct |
695 ms |
97404 KB |
Output is correct |
31 |
Correct |
790 ms |
97524 KB |
Output is correct |
32 |
Correct |
787 ms |
133940 KB |
Output is correct |
33 |
Correct |
873 ms |
103828 KB |
Output is correct |
34 |
Correct |
304 ms |
21040 KB |
Output is correct |
35 |
Correct |
955 ms |
97260 KB |
Output is correct |
36 |
Correct |
831 ms |
107248 KB |
Output is correct |
37 |
Correct |
837 ms |
97748 KB |
Output is correct |
38 |
Correct |
859 ms |
103772 KB |
Output is correct |
39 |
Correct |
778 ms |
86020 KB |
Output is correct |
40 |
Correct |
900 ms |
102316 KB |
Output is correct |
41 |
Correct |
748 ms |
98384 KB |
Output is correct |
42 |
Correct |
735 ms |
107280 KB |
Output is correct |
43 |
Correct |
964 ms |
99104 KB |
Output is correct |
44 |
Correct |
881 ms |
97880 KB |
Output is correct |
45 |
Correct |
603 ms |
87388 KB |
Output is correct |
46 |
Correct |
694 ms |
86904 KB |
Output is correct |
47 |
Correct |
729 ms |
97580 KB |
Output is correct |
48 |
Correct |
755 ms |
97448 KB |
Output is correct |
49 |
Correct |
661 ms |
97576 KB |
Output is correct |
50 |
Correct |
736 ms |
97572 KB |
Output is correct |
51 |
Correct |
804 ms |
101032 KB |
Output is correct |
52 |
Correct |
801 ms |
101036 KB |
Output is correct |