#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
struct DSU{
int n;
vector<int> lab;
void init(int _n){
n=_n;
lab.assign(n+1, -1);
}
int find_set(int u){
return lab[u]<0?u:lab[u]=find_set(lab[u]);
}
void union_sets(int u, int v){
u=find_set(u), v=find_set(v);
if (u!=v){
if (lab[u]>lab[v]) swap(u, v);
lab[u]+=lab[v];
lab[v]=u;
}
}
bool check(int u, int v){
return find_set(u)==find_set(v);
}
} dsu;
bool check[3000][3000];
vector<int> g[3000];
vector<int> vl[3000], vr[3000];
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 M=X.size();
for (int i=0; i<M; ++i) g[X[i]].push_back(Y[i]), g[Y[i]].push_back(X[i]);
int Q=S.size();
for (int i=0; i<Q; ++i){
vl[L[i]].push_back(i), vr[R[i]].push_back(i);
for (int j=0; j<N; ++j) check[i][j]=1;
}
dsu.init(N);
for (int i=N-1; i>=0; --i){
for (int j:g[i]) if (j>i) dsu.union_sets(i, j);
for (int j:vl[i]){
for (int k=i; k<N; ++k) check[j][k]&=dsu.check(S[j], k);
}
}
dsu.init(N);
for (int i=0; i<N; ++i){
for (int j:g[i]) if (j<i) dsu.union_sets(i, j);
for (int j:vr[i]){
for (int k=0; k<=i; ++k) check[j][k]&=dsu.check(E[j], k);
}
}
vector<int> ans(Q);
for (int i=0; i<Q; ++i) ans[i]=*max_element(check[i]+L[i], check[i]+R[i]+1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
916 KB |
Output is correct |
2 |
Correct |
0 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
916 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
0 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
860 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
916 KB |
Output is correct |
2 |
Correct |
0 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
916 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
0 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
860 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
37 ms |
9820 KB |
Output is correct |
11 |
Correct |
38 ms |
9820 KB |
Output is correct |
12 |
Correct |
34 ms |
9816 KB |
Output is correct |
13 |
Correct |
33 ms |
9820 KB |
Output is correct |
14 |
Correct |
32 ms |
9820 KB |
Output is correct |
15 |
Correct |
39 ms |
9980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
119 ms |
48724 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
916 KB |
Output is correct |
2 |
Correct |
0 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
916 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
0 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
860 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
37 ms |
9820 KB |
Output is correct |
11 |
Correct |
38 ms |
9820 KB |
Output is correct |
12 |
Correct |
34 ms |
9816 KB |
Output is correct |
13 |
Correct |
33 ms |
9820 KB |
Output is correct |
14 |
Correct |
32 ms |
9820 KB |
Output is correct |
15 |
Correct |
39 ms |
9980 KB |
Output is correct |
16 |
Runtime error |
119 ms |
48724 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |