#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 25;
const int B = 21;
pair <int, int> edges[MAXN];
array <int, 4> queries[MAXN];
int ans[MAXN];
int n, m, q;
struct DSU {
int par[MAXN];
void init (int n) {
for (int i = 1; i <= n; i++) par[i] = i;
}
int find (int x) {
return par[x] == x ? x : par[x] = find(par[x]);
}
bool merge (int x, int y) {
x = find(x), y = find(y);
if (x == y) return 0;
if (x > y) swap(x, y);
par[x] = y;
return 1;
}
} dd;
struct tree {
int p[MAXN]; vector <int> adj[MAXN];
int cnt;
int in[MAXN], out[MAXN], tt, dp[MAXN];
int sparse[B][MAXN];
void init (int n) {
cnt = n;
}
void link (int a, int b) {
cnt++; p[a] = p[b] = cnt;
adj[cnt].push_back(a);
adj[cnt].push_back(b);
}
void dfs (int pos, bool c) {
if (adj[pos].empty()) {
dp[pos] = pos;
return;
}
for (auto j : adj[pos]) {
dfs(j, c);
}
if (!c) {
if (dp[adj[pos][0]] > dp[adj[pos][1]]) swap(adj[pos][0], adj[pos][1]);
dp[pos] = dp[adj[pos][0]];
} else {
if (dp[adj[pos][0]] < dp[adj[pos][1]]) swap(adj[pos][0], adj[pos][1]);
dp[pos] = dp[adj[pos][0]];
}
}
void dfs2 (int pos) {
if (adj[pos].empty()) {
in[pos] = out[pos] = ++tt;
return;
}
for (auto j : adj[pos]) {
dfs2(j);
}
in[pos] = in[adj[pos][0]];
out[pos] = out[adj[pos][1]];
}
void build (bool c) {
dfs(cnt, c);
dfs2(cnt);
for (int i = 1; i <= cnt; i++) {
sparse[0][i] = p[i];
}
for (int i = 1; i < B; i++) {
for (int j = 1; j <= cnt; j++) {
sparse[i][j] = sparse[i - 1][sparse[i - 1][j]];
}
}
}
pair <int, int> get (int x, int y, bool c) {
for (int i = B - 1; i >= 0; i--) {
if (!sparse[i][x]) continue;
if (!c) {
if (dp[sparse[i][x]] >= y) x = sparse[i][x];
} else {
if (dp[sparse[i][x]] <= y) x = sparse[i][x];
}
}
return {in[x], out[x]};
}
} cur[2];
vector<int> check_validity (int N, vector <int> X, vector<int> Y,
vector<int> S, vector<int> E,
vector<int> L, vector<int> R) {
n = N; m = (int)X.size(); q = S.size();
int dp[n][n], dq[n][n]; //min edge, max edge
for (int i = 0; i < n; i++) {
dp[i][i] = dq[i][i] = i;
for (int j = 0; j < n; j++) {
dp[i][j] = -1e9; dq[i][j] = 1e9;
}
}
for (int i = 0; i < m; i++) {
dp[X[i]][Y[i]] = dp[Y[i]][X[i]] = min(Y[i], X[i]);
dq[X[i]][Y[i]] = dq[Y[i]][X[i]] = max(Y[i], X[i]);
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = max(dp[i][j], min(dp[i][k], dp[k][j]));
dq[i][j] = min(dq[i][j], max(dq[i][k], dq[k][j]));
}
}
}
vector <int> ret;
for (int i = 0; i < q; i++) {
int flag = 0;
int a = S[i], b = E[i];
for (int j = 0; j < n; j++) {
flag |= dp[a][j] >= L[i] && dq[j][b] <= R[i];
}
ret.push_back(flag);
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
24924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
24924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
489 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
24924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |