Submission #701018

# Submission time Handle Problem Language Result Execution time Memory
701018 2023-02-19T18:40:42 Z BingDong Jail (JOI22_jail) C++17
100 / 100
441 ms 72192 KB
#include <iostream>
#include <vector>
using namespace std;

int read() {
  int s = 0, w = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (isdigit(c))
    s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  return s * w;
}

const int N = 1.2e5, Q = 1.2e5, N_ = (1 << 17) * 4 + Q;

vector<int> g[N];
int p[N], c[N], o[N], z[N], tt;

int dfs1(int i) {
  int s = 1, x = 0;
  c[i] = -1;
  for (int j : g[i])
    if (p[i] != j) {
      p[j] = i;
      int y = dfs1(j);
      if (y > x)
        x = y, c[i] = j;
      s += y;
    }
  return s;
}

void dfs2(int i, int z_) {
  z[i] = z_;
  o[i] = tt++;
  if (c[i] != -1)
    dfs2(c[i], z_);
  for (int j : g[i])
    if (p[i] != j && c[i] != j)
      dfs2(j, j);
}

int n_, d[N_];
vector<int> g_[N_];

void add_edge(int i, int j) {
  g_[i].push_back(j), d[j]++;
}

void dfs(int i) {
  if (d[i] == 0) {
    d[i] = -1;
    for (int j : g_[i]) {
      d[j]--;
      dfs(j);
    }
  }
}

void add_range(int l, int r, int s, int t, int h) {
  int x, y;
  x = l + (o[t] == l), y = r - (o[t] == r);
  for (x += n_, y += n_; x <= y; x >>= 1, y >>= 1) {
    if ((x & 1) == 1)
      add_edge(n_ * 4 + h, x), x++;
    if ((y & 1) == 0)
      add_edge(n_ * 4 + h, y), y--;
  }
  x = l + (o[s] == l), y = r - (o[s] == r);
  for (x += n_, y += n_; x <= y; x >>= 1, y >>= 1) {
    if ((x & 1) == 1)
      add_edge(n_ * 2 + x, n_ * 4 + h), x++;
    if ((y & 1) == 0)
      add_edge(n_ * 2 + y, n_ * 4 + h), y--;
  }
}

int main() {
  int t = read();
  while (t--) {
    int n = read();
    for (int h = 0; h < n - 1; h++) {
      int i = read() - 1, j = read() - 1;
      g[i].push_back(j), g[j].push_back(i);
    }
    p[0] = -1;
    dfs1(0);
    tt = 0;
    dfs2(0, 0);
    n_ = 1;
    while (n_ < n)
      n_ <<= 1;
    for (int i = 1; i < n_; i++) {
      add_edge(i, i << 1 | 0);
      add_edge(i, i << 1 | 1);
      add_edge(n_ * 2 + (i << 1 | 0), n_ * 2 + i);
      add_edge(n_ * 2 + (i << 1 | 1), n_ * 2 + i);
    }
    int q = read();
    for (int h = 0; h < q; h++) {
      int s = read() - 1, t = read() - 1, i = s, j = t;
      while (z[i] != z[j])
        if (o[z[i]] > o[z[j]])
          add_range(o[z[i]], o[i], s, t, h), i = p[z[i]];
        else
          add_range(o[z[j]], o[j], s, t, h), j = p[z[j]];
      add_range(min(o[i], o[j]), max(o[i], o[j]), s, t, h);
      add_edge(n_ + o[t], n_ * 4 + h);
      add_edge(n_ * 4 + h, n_ * 3 + o[s]);
    }
    for (int i = 1; i < n_ * 4 + q; i++)
      dfs(i);
    bool yes = 1;
    for (int i = 1; i < n_ * 4 + q; i++)
      yes &= d[i] == -1;
    printf(yes ? "Yes\n" : "No\n");
    for (int i = 0; i < n; i++)
      g[i].clear();
    for (int i = 1; i < n_ * 4 + q; i++) {
      g_[i].clear();
      d[i] = 0;
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 18260 KB Output is correct
2 Correct 12 ms 18252 KB Output is correct
3 Correct 10 ms 18252 KB Output is correct
4 Correct 15 ms 18548 KB Output is correct
5 Correct 23 ms 18900 KB Output is correct
6 Correct 10 ms 18268 KB Output is correct
7 Correct 10 ms 18260 KB Output is correct
8 Correct 11 ms 18380 KB Output is correct
9 Correct 42 ms 20660 KB Output is correct
10 Correct 67 ms 48324 KB Output is correct
11 Correct 15 ms 18424 KB Output is correct
12 Correct 29 ms 18944 KB Output is correct
13 Correct 111 ms 53348 KB Output is correct
14 Correct 102 ms 53464 KB Output is correct
15 Correct 229 ms 58148 KB Output is correct
16 Correct 337 ms 72192 KB Output is correct
17 Correct 143 ms 62388 KB Output is correct
18 Correct 99 ms 56168 KB Output is correct
19 Correct 155 ms 60900 KB Output is correct
20 Correct 133 ms 60884 KB Output is correct
21 Correct 146 ms 61512 KB Output is correct
22 Correct 73 ms 52208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 18260 KB Output is correct
2 Correct 11 ms 18232 KB Output is correct
3 Correct 11 ms 18288 KB Output is correct
4 Correct 11 ms 18260 KB Output is correct
5 Correct 10 ms 18260 KB Output is correct
6 Correct 14 ms 18268 KB Output is correct
7 Correct 11 ms 18352 KB Output is correct
8 Correct 11 ms 18260 KB Output is correct
9 Correct 11 ms 18260 KB Output is correct
10 Correct 11 ms 18244 KB Output is correct
11 Correct 12 ms 18260 KB Output is correct
12 Correct 10 ms 18260 KB Output is correct
13 Correct 10 ms 18264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 18260 KB Output is correct
2 Correct 11 ms 18232 KB Output is correct
3 Correct 11 ms 18288 KB Output is correct
4 Correct 11 ms 18260 KB Output is correct
5 Correct 10 ms 18260 KB Output is correct
6 Correct 14 ms 18268 KB Output is correct
7 Correct 11 ms 18352 KB Output is correct
8 Correct 11 ms 18260 KB Output is correct
9 Correct 11 ms 18260 KB Output is correct
10 Correct 11 ms 18244 KB Output is correct
11 Correct 12 ms 18260 KB Output is correct
12 Correct 10 ms 18260 KB Output is correct
13 Correct 10 ms 18264 KB Output is correct
14 Correct 10 ms 18260 KB Output is correct
15 Correct 12 ms 18260 KB Output is correct
16 Correct 10 ms 18260 KB Output is correct
17 Correct 11 ms 18356 KB Output is correct
18 Correct 10 ms 18260 KB Output is correct
19 Correct 10 ms 18260 KB Output is correct
20 Correct 11 ms 18260 KB Output is correct
21 Correct 11 ms 18272 KB Output is correct
22 Correct 11 ms 18260 KB Output is correct
23 Correct 12 ms 18256 KB Output is correct
24 Correct 10 ms 18256 KB Output is correct
25 Correct 11 ms 18260 KB Output is correct
26 Correct 10 ms 18260 KB Output is correct
27 Correct 11 ms 18328 KB Output is correct
28 Correct 13 ms 18252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 18260 KB Output is correct
2 Correct 11 ms 18232 KB Output is correct
3 Correct 11 ms 18288 KB Output is correct
4 Correct 11 ms 18260 KB Output is correct
5 Correct 10 ms 18260 KB Output is correct
6 Correct 14 ms 18268 KB Output is correct
7 Correct 11 ms 18352 KB Output is correct
8 Correct 11 ms 18260 KB Output is correct
9 Correct 11 ms 18260 KB Output is correct
10 Correct 11 ms 18244 KB Output is correct
11 Correct 12 ms 18260 KB Output is correct
12 Correct 10 ms 18260 KB Output is correct
13 Correct 10 ms 18264 KB Output is correct
14 Correct 10 ms 18260 KB Output is correct
15 Correct 12 ms 18260 KB Output is correct
16 Correct 10 ms 18260 KB Output is correct
17 Correct 11 ms 18356 KB Output is correct
18 Correct 10 ms 18260 KB Output is correct
19 Correct 10 ms 18260 KB Output is correct
20 Correct 11 ms 18260 KB Output is correct
21 Correct 11 ms 18272 KB Output is correct
22 Correct 11 ms 18260 KB Output is correct
23 Correct 12 ms 18256 KB Output is correct
24 Correct 10 ms 18256 KB Output is correct
25 Correct 11 ms 18260 KB Output is correct
26 Correct 10 ms 18260 KB Output is correct
27 Correct 11 ms 18328 KB Output is correct
28 Correct 13 ms 18252 KB Output is correct
29 Correct 13 ms 18388 KB Output is correct
30 Correct 12 ms 18268 KB Output is correct
31 Correct 12 ms 18260 KB Output is correct
32 Correct 13 ms 18272 KB Output is correct
33 Correct 13 ms 18268 KB Output is correct
34 Correct 12 ms 18304 KB Output is correct
35 Correct 11 ms 18260 KB Output is correct
36 Correct 11 ms 18388 KB Output is correct
37 Correct 10 ms 18268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 18260 KB Output is correct
2 Correct 11 ms 18232 KB Output is correct
3 Correct 11 ms 18288 KB Output is correct
4 Correct 11 ms 18260 KB Output is correct
5 Correct 10 ms 18260 KB Output is correct
6 Correct 14 ms 18268 KB Output is correct
7 Correct 11 ms 18352 KB Output is correct
8 Correct 11 ms 18260 KB Output is correct
9 Correct 11 ms 18260 KB Output is correct
10 Correct 11 ms 18244 KB Output is correct
11 Correct 12 ms 18260 KB Output is correct
12 Correct 10 ms 18260 KB Output is correct
13 Correct 10 ms 18264 KB Output is correct
14 Correct 10 ms 18260 KB Output is correct
15 Correct 12 ms 18260 KB Output is correct
16 Correct 10 ms 18260 KB Output is correct
17 Correct 11 ms 18356 KB Output is correct
18 Correct 10 ms 18260 KB Output is correct
19 Correct 10 ms 18260 KB Output is correct
20 Correct 11 ms 18260 KB Output is correct
21 Correct 11 ms 18272 KB Output is correct
22 Correct 11 ms 18260 KB Output is correct
23 Correct 12 ms 18256 KB Output is correct
24 Correct 10 ms 18256 KB Output is correct
25 Correct 11 ms 18260 KB Output is correct
26 Correct 10 ms 18260 KB Output is correct
27 Correct 11 ms 18328 KB Output is correct
28 Correct 13 ms 18252 KB Output is correct
29 Correct 13 ms 18388 KB Output is correct
30 Correct 12 ms 18268 KB Output is correct
31 Correct 12 ms 18260 KB Output is correct
32 Correct 13 ms 18272 KB Output is correct
33 Correct 13 ms 18268 KB Output is correct
34 Correct 12 ms 18304 KB Output is correct
35 Correct 11 ms 18260 KB Output is correct
36 Correct 11 ms 18388 KB Output is correct
37 Correct 10 ms 18268 KB Output is correct
38 Correct 33 ms 21296 KB Output is correct
39 Correct 64 ms 49084 KB Output is correct
40 Correct 47 ms 21148 KB Output is correct
41 Correct 45 ms 21044 KB Output is correct
42 Correct 33 ms 21168 KB Output is correct
43 Correct 32 ms 20832 KB Output is correct
44 Correct 18 ms 18860 KB Output is correct
45 Correct 75 ms 39764 KB Output is correct
46 Correct 90 ms 39804 KB Output is correct
47 Correct 78 ms 44432 KB Output is correct
48 Correct 75 ms 44420 KB Output is correct
49 Correct 68 ms 39976 KB Output is correct
50 Correct 70 ms 39972 KB Output is correct
51 Correct 60 ms 41264 KB Output is correct
52 Correct 59 ms 41248 KB Output is correct
53 Correct 21 ms 20180 KB Output is correct
54 Correct 123 ms 39764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 18260 KB Output is correct
2 Correct 10 ms 18260 KB Output is correct
3 Correct 10 ms 18256 KB Output is correct
4 Correct 10 ms 18280 KB Output is correct
5 Correct 16 ms 18388 KB Output is correct
6 Correct 11 ms 18236 KB Output is correct
7 Correct 10 ms 18272 KB Output is correct
8 Correct 10 ms 18260 KB Output is correct
9 Correct 13 ms 18256 KB Output is correct
10 Correct 11 ms 18260 KB Output is correct
11 Correct 10 ms 18244 KB Output is correct
12 Correct 11 ms 18268 KB Output is correct
13 Correct 25 ms 18792 KB Output is correct
14 Correct 38 ms 19048 KB Output is correct
15 Correct 29 ms 18944 KB Output is correct
16 Correct 129 ms 41568 KB Output is correct
17 Correct 254 ms 49868 KB Output is correct
18 Correct 358 ms 60032 KB Output is correct
19 Correct 170 ms 43212 KB Output is correct
20 Correct 146 ms 43124 KB Output is correct
21 Correct 169 ms 43164 KB Output is correct
22 Correct 215 ms 49836 KB Output is correct
23 Correct 146 ms 49644 KB Output is correct
24 Correct 165 ms 49888 KB Output is correct
25 Correct 167 ms 49872 KB Output is correct
26 Correct 170 ms 50032 KB Output is correct
27 Correct 235 ms 56216 KB Output is correct
28 Correct 145 ms 48656 KB Output is correct
29 Correct 155 ms 48660 KB Output is correct
30 Correct 244 ms 47060 KB Output is correct
31 Correct 135 ms 44216 KB Output is correct
32 Correct 189 ms 47164 KB Output is correct
33 Correct 152 ms 44372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 18260 KB Output is correct
2 Correct 12 ms 18252 KB Output is correct
3 Correct 10 ms 18252 KB Output is correct
4 Correct 15 ms 18548 KB Output is correct
5 Correct 23 ms 18900 KB Output is correct
6 Correct 10 ms 18268 KB Output is correct
7 Correct 10 ms 18260 KB Output is correct
8 Correct 11 ms 18380 KB Output is correct
9 Correct 42 ms 20660 KB Output is correct
10 Correct 67 ms 48324 KB Output is correct
11 Correct 15 ms 18424 KB Output is correct
12 Correct 29 ms 18944 KB Output is correct
13 Correct 111 ms 53348 KB Output is correct
14 Correct 102 ms 53464 KB Output is correct
15 Correct 229 ms 58148 KB Output is correct
16 Correct 337 ms 72192 KB Output is correct
17 Correct 143 ms 62388 KB Output is correct
18 Correct 99 ms 56168 KB Output is correct
19 Correct 155 ms 60900 KB Output is correct
20 Correct 133 ms 60884 KB Output is correct
21 Correct 146 ms 61512 KB Output is correct
22 Correct 73 ms 52208 KB Output is correct
23 Correct 10 ms 18260 KB Output is correct
24 Correct 11 ms 18232 KB Output is correct
25 Correct 11 ms 18288 KB Output is correct
26 Correct 11 ms 18260 KB Output is correct
27 Correct 10 ms 18260 KB Output is correct
28 Correct 14 ms 18268 KB Output is correct
29 Correct 11 ms 18352 KB Output is correct
30 Correct 11 ms 18260 KB Output is correct
31 Correct 11 ms 18260 KB Output is correct
32 Correct 11 ms 18244 KB Output is correct
33 Correct 12 ms 18260 KB Output is correct
34 Correct 10 ms 18260 KB Output is correct
35 Correct 10 ms 18264 KB Output is correct
36 Correct 10 ms 18260 KB Output is correct
37 Correct 12 ms 18260 KB Output is correct
38 Correct 10 ms 18260 KB Output is correct
39 Correct 11 ms 18356 KB Output is correct
40 Correct 10 ms 18260 KB Output is correct
41 Correct 10 ms 18260 KB Output is correct
42 Correct 11 ms 18260 KB Output is correct
43 Correct 11 ms 18272 KB Output is correct
44 Correct 11 ms 18260 KB Output is correct
45 Correct 12 ms 18256 KB Output is correct
46 Correct 10 ms 18256 KB Output is correct
47 Correct 11 ms 18260 KB Output is correct
48 Correct 10 ms 18260 KB Output is correct
49 Correct 11 ms 18328 KB Output is correct
50 Correct 13 ms 18252 KB Output is correct
51 Correct 13 ms 18388 KB Output is correct
52 Correct 12 ms 18268 KB Output is correct
53 Correct 12 ms 18260 KB Output is correct
54 Correct 13 ms 18272 KB Output is correct
55 Correct 13 ms 18268 KB Output is correct
56 Correct 12 ms 18304 KB Output is correct
57 Correct 11 ms 18260 KB Output is correct
58 Correct 11 ms 18388 KB Output is correct
59 Correct 10 ms 18268 KB Output is correct
60 Correct 33 ms 21296 KB Output is correct
61 Correct 64 ms 49084 KB Output is correct
62 Correct 47 ms 21148 KB Output is correct
63 Correct 45 ms 21044 KB Output is correct
64 Correct 33 ms 21168 KB Output is correct
65 Correct 32 ms 20832 KB Output is correct
66 Correct 18 ms 18860 KB Output is correct
67 Correct 75 ms 39764 KB Output is correct
68 Correct 90 ms 39804 KB Output is correct
69 Correct 78 ms 44432 KB Output is correct
70 Correct 75 ms 44420 KB Output is correct
71 Correct 68 ms 39976 KB Output is correct
72 Correct 70 ms 39972 KB Output is correct
73 Correct 60 ms 41264 KB Output is correct
74 Correct 59 ms 41248 KB Output is correct
75 Correct 21 ms 20180 KB Output is correct
76 Correct 123 ms 39764 KB Output is correct
77 Correct 10 ms 18260 KB Output is correct
78 Correct 10 ms 18260 KB Output is correct
79 Correct 10 ms 18256 KB Output is correct
80 Correct 10 ms 18280 KB Output is correct
81 Correct 16 ms 18388 KB Output is correct
82 Correct 11 ms 18236 KB Output is correct
83 Correct 10 ms 18272 KB Output is correct
84 Correct 10 ms 18260 KB Output is correct
85 Correct 13 ms 18256 KB Output is correct
86 Correct 11 ms 18260 KB Output is correct
87 Correct 10 ms 18244 KB Output is correct
88 Correct 11 ms 18268 KB Output is correct
89 Correct 25 ms 18792 KB Output is correct
90 Correct 38 ms 19048 KB Output is correct
91 Correct 29 ms 18944 KB Output is correct
92 Correct 129 ms 41568 KB Output is correct
93 Correct 254 ms 49868 KB Output is correct
94 Correct 358 ms 60032 KB Output is correct
95 Correct 170 ms 43212 KB Output is correct
96 Correct 146 ms 43124 KB Output is correct
97 Correct 169 ms 43164 KB Output is correct
98 Correct 215 ms 49836 KB Output is correct
99 Correct 146 ms 49644 KB Output is correct
100 Correct 165 ms 49888 KB Output is correct
101 Correct 167 ms 49872 KB Output is correct
102 Correct 170 ms 50032 KB Output is correct
103 Correct 235 ms 56216 KB Output is correct
104 Correct 145 ms 48656 KB Output is correct
105 Correct 155 ms 48660 KB Output is correct
106 Correct 244 ms 47060 KB Output is correct
107 Correct 135 ms 44216 KB Output is correct
108 Correct 189 ms 47164 KB Output is correct
109 Correct 152 ms 44372 KB Output is correct
110 Correct 34 ms 19332 KB Output is correct
111 Correct 25 ms 18900 KB Output is correct
112 Correct 248 ms 56428 KB Output is correct
113 Correct 158 ms 48400 KB Output is correct
114 Correct 183 ms 52536 KB Output is correct
115 Correct 61 ms 39956 KB Output is correct
116 Correct 166 ms 44208 KB Output is correct
117 Correct 441 ms 70040 KB Output is correct
118 Correct 94 ms 39884 KB Output is correct
119 Correct 96 ms 39864 KB Output is correct
120 Correct 20 ms 21076 KB Output is correct
121 Correct 243 ms 45500 KB Output is correct
122 Correct 189 ms 45516 KB Output is correct
123 Correct 144 ms 50852 KB Output is correct
124 Correct 127 ms 50844 KB Output is correct
125 Correct 155 ms 51444 KB Output is correct
126 Correct 373 ms 70304 KB Output is correct
127 Correct 188 ms 58924 KB Output is correct
128 Correct 153 ms 59104 KB Output is correct
129 Correct 194 ms 59068 KB Output is correct
130 Correct 156 ms 59180 KB Output is correct