답안 #957135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957135 2024-04-03T04:43:47 Z NeroZein Jail (JOI22_jail) C++17
61 / 100
5000 ms 31840 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

const int LOG = 18;
const int N = 120005;

int dep[N];
int vis[N];
int pr[LOG][N];
int a[N], b[N];
vector<int> g[N], t[N];

void dfs(int v, int p) {
  for (int u : g[v]) {
    if (u == p) continue; 
    dep[u] = dep[v] + 1; 
    pr[0][u] = v;
    for (int j = 1; j < LOG; ++j) {
      pr[j][u] = pr[j - 1][pr[j - 1][u]];
    }
    dfs(u, v);
  }
}

int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int j = 0; j < LOG; ++j) {
    if ((dep[u] - dep[v]) >> j & 1) {
      u = pr[j][u];
    }
  }
  if (u == v) return v;
  for (int j = LOG - 1; j >= 0; --j) {
    if (pr[j][u] != pr[j][v]) {
      u = pr[j][u], v = pr[j][v];
    }
  }
  return pr[0][v];
}

int onPath(int x, int y, int z) {
  int lc1 = lca(x, y);
  int lc2 = lca(x, z);
  int lc3 = lca(y, z);
  return (lc1 ^ lc2 ^ lc3) == z; 
}

bool dfs2(int v) {
  if (vis[v] == 1) return true; 
  if (vis[v] == 2) return false; 
  vis[v] = 1;
  bool ret = false; 
  for (int u : t[v]) {
    ret |= dfs2(u); 
  }
  vis[v] = 2; 
  return ret; 
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    for(int i = 0; i < n - 1; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    int m;
    cin >> m;
    for (int i = 1; i <= m; ++i) {
      cin >> a[i] >> b[i];
    }
    dfs(1, 0);
    for (int i = 1; i <= m; ++i) {
      for (int j = 1; j <= m; ++j) {
        if (i == j) continue; 
        if (onPath(a[i], b[i], a[j])) {
          t[j].push_back(i);
        }
        if (onPath(a[i], b[i], b[j])) {
          t[i].push_back(j);
        }
      }
    }
    bool cycle = false; 
    for (int i = 1; i <= m; ++i) {
      cycle |= dfs2(i);
    }
    cout << (cycle ? "No" : "Yes") << '\n';  
    fill(vis + 1, vis + 1 + m, 0);
    fill(t + 1, t + 1 + m, vector<int>());
    fill(g + 1, g + 1 + n, vector<int>());
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 11 ms 15196 KB Output is correct
5 Correct 19 ms 15708 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 4 ms 15056 KB Output is correct
8 Correct 47 ms 15100 KB Output is correct
9 Correct 1822 ms 18640 KB Output is correct
10 Correct 127 ms 31824 KB Output is correct
11 Correct 17 ms 14936 KB Output is correct
12 Correct 548 ms 16024 KB Output is correct
13 Execution timed out 5027 ms 31576 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 15000 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14956 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 15192 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 15000 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14956 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 15192 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 4 ms 15076 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 15028 KB Output is correct
25 Correct 4 ms 14940 KB Output is correct
26 Correct 3 ms 15032 KB Output is correct
27 Correct 4 ms 15196 KB Output is correct
28 Correct 3 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 15000 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14956 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 15192 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 4 ms 15076 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 15028 KB Output is correct
25 Correct 4 ms 14940 KB Output is correct
26 Correct 3 ms 15032 KB Output is correct
27 Correct 4 ms 15196 KB Output is correct
28 Correct 3 ms 14940 KB Output is correct
29 Correct 52 ms 15352 KB Output is correct
30 Correct 27 ms 14936 KB Output is correct
31 Correct 27 ms 14940 KB Output is correct
32 Correct 20 ms 14936 KB Output is correct
33 Correct 5 ms 14940 KB Output is correct
34 Correct 40 ms 15336 KB Output is correct
35 Correct 63 ms 15332 KB Output is correct
36 Correct 33 ms 14936 KB Output is correct
37 Correct 28 ms 14936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 15000 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14956 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 15192 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 4 ms 15076 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 15028 KB Output is correct
25 Correct 4 ms 14940 KB Output is correct
26 Correct 3 ms 15032 KB Output is correct
27 Correct 4 ms 15196 KB Output is correct
28 Correct 3 ms 14940 KB Output is correct
29 Correct 52 ms 15352 KB Output is correct
30 Correct 27 ms 14936 KB Output is correct
31 Correct 27 ms 14940 KB Output is correct
32 Correct 20 ms 14936 KB Output is correct
33 Correct 5 ms 14940 KB Output is correct
34 Correct 40 ms 15336 KB Output is correct
35 Correct 63 ms 15332 KB Output is correct
36 Correct 33 ms 14936 KB Output is correct
37 Correct 28 ms 14936 KB Output is correct
38 Correct 1819 ms 18888 KB Output is correct
39 Correct 126 ms 31840 KB Output is correct
40 Correct 1753 ms 17548 KB Output is correct
41 Correct 1348 ms 16572 KB Output is correct
42 Correct 1216 ms 18104 KB Output is correct
43 Correct 41 ms 16476 KB Output is correct
44 Correct 884 ms 15596 KB Output is correct
45 Correct 210 ms 21340 KB Output is correct
46 Correct 208 ms 21084 KB Output is correct
47 Correct 266 ms 25740 KB Output is correct
48 Correct 248 ms 25828 KB Output is correct
49 Correct 234 ms 21372 KB Output is correct
50 Correct 252 ms 21340 KB Output is correct
51 Correct 68 ms 22620 KB Output is correct
52 Correct 64 ms 22588 KB Output is correct
53 Correct 744 ms 15684 KB Output is correct
54 Correct 149 ms 21336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 2 ms 14940 KB Output is correct
4 Correct 3 ms 14936 KB Output is correct
5 Correct 18 ms 15164 KB Output is correct
6 Correct 3 ms 14936 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14936 KB Output is correct
9 Correct 3 ms 14992 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 33 ms 15044 KB Output is correct
13 Correct 437 ms 15584 KB Output is correct
14 Correct 205 ms 15696 KB Output is correct
15 Correct 323 ms 15768 KB Output is correct
16 Execution timed out 5029 ms 21436 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 2 ms 14940 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 11 ms 15196 KB Output is correct
5 Correct 19 ms 15708 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 4 ms 15056 KB Output is correct
8 Correct 47 ms 15100 KB Output is correct
9 Correct 1822 ms 18640 KB Output is correct
10 Correct 127 ms 31824 KB Output is correct
11 Correct 17 ms 14936 KB Output is correct
12 Correct 548 ms 16024 KB Output is correct
13 Execution timed out 5027 ms 31576 KB Time limit exceeded
14 Halted 0 ms 0 KB -