Submission #1073419

# Submission time Handle Problem Language Result Execution time Memory
1073419 2024-08-24T14:24:46 Z NeroZein The Ties That Guide Us (CEOI23_incursion) C++17
100 / 100
277 ms 17392 KB
#include "incursion.h"
#include <bits/stdc++.h>
 
using namespace std; 
 
vector<int> mark(vector<pair<int, int>> F, int safe) {
  int n = (int) F.size() + 1; 
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; ++i) {
    auto [u, v] = F[i];
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u); 
  }
  vector<int> sz(n); 
  vector<int> dist(n);
  vector<int> ties(n);
  function<void(int, int)> dfs = [&](int v, int p) {
    sz[v] = 1;
    for (int u : g[v]) {
      if (u == p) {
        continue; 
      }
      dist[u] = dist[v] + 1; 
      dfs(u, v);
      sz[v] += sz[u];
    }
  };
  --safe;
  dfs(safe, safe); 
  for (int v = 0; v < n; ++v) {
    int mx = 0; 
    for (int u : g[v]) {
      if (dist[v] != dist[u] + 1) {
        mx = max(mx, sz[u]);   
      } else {
        mx = max(mx, n - sz[v]);
      }
    }
    for (int u : g[v]) {
      if (dist[v] == dist[u] + 1) {
        ties[v] = mx == (n - sz[v]);
      }
    }
  }
  return ties;
}
 
void locate(vector<pair<int, int>> F, int curr, int t) {
  int n = (int) F.size() + 1; 
  vector<vector<int>> g(n); 
  for (int i = 0; i < n - 1; ++i) {
    auto [u, v] = F[i];
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u); 
  }
  vector<int> sz(n); 
  function<void(int, int)> dfs = [&](int v, int p) {
    sz[v] = 1;
    for (int u : g[v]) {
      if (u == p) {
        continue;
      }
      dfs(u, v);
      sz[v] += sz[u]; 
    }
  };
  --curr; 
  dfs(curr, curr); 
  function<bool(int, int, int)> dfs2 = [&](int v, int p, int tt) {
    vector<pair<int, int>> vec; 
    for (int u : g[v]) {
      int s = (sz[u] < sz[v] ? sz[u] : n - sz[v]);
      vec.push_back({s, u});
    }
    sort(vec.begin(), vec.end());
    if (tt == 1) {
      int x = vec.back().first;
      reverse(vec.begin(), vec.end());
      while (vec.back().first < x) {
        vec.pop_back();
      }
    } else {
      int x = vec.back().first; 
      while (vec.back().first == x) {
        vec.pop_back();
      }
      reverse(vec.begin(), vec.end());
    }
    for (auto [s, u] : vec) {
      if (u == p) {
        continue; 
      }
      int nt = visit(u + 1); 
      g[v].erase(find(g[v].begin(), g[v].end(), u));
      bool f = dfs2(u, v, nt);         
      if (f == false) {
        visit(v + 1); 
      } else {
        return true; 
      }
    }
    return !tt;
  };
  dfs2(curr, curr, t);
  return;
}

Compilation message

interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 764 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 233 ms 15808 KB Correct
2 Correct 221 ms 15820 KB Correct
3 Correct 106 ms 16004 KB Correct
4 Correct 102 ms 13640 KB Correct
5 Correct 207 ms 15384 KB Correct
6 Correct 80 ms 11924 KB Correct
7 Correct 90 ms 12004 KB Correct
8 Correct 228 ms 16000 KB Correct
9 Correct 215 ms 15852 KB Correct
10 Correct 140 ms 13472 KB Correct
11 Correct 103 ms 14384 KB Correct
12 Correct 268 ms 17392 KB Correct
13 Correct 88 ms 11936 KB Correct
14 Correct 88 ms 11604 KB Correct
15 Correct 204 ms 15804 KB Correct
16 Correct 211 ms 15900 KB Correct
17 Correct 139 ms 13800 KB Correct
18 Correct 105 ms 14860 KB Correct
19 Correct 157 ms 14980 KB Correct
20 Correct 77 ms 11940 KB Correct
21 Correct 80 ms 11800 KB Correct
22 Correct 239 ms 15860 KB Correct
23 Correct 201 ms 16324 KB Correct
24 Correct 102 ms 13668 KB Correct
25 Correct 93 ms 15524 KB Correct
26 Correct 83 ms 13728 KB Correct
27 Correct 83 ms 11792 KB Correct
28 Correct 86 ms 11872 KB Correct
29 Correct 218 ms 16076 KB Correct
30 Correct 228 ms 16032 KB Correct
31 Correct 99 ms 12952 KB Correct
32 Correct 238 ms 16172 KB Correct
33 Correct 242 ms 16064 KB Correct
34 Correct 86 ms 12012 KB Correct
35 Correct 75 ms 11864 KB Correct
36 Correct 208 ms 15828 KB Correct
37 Correct 212 ms 16016 KB Correct
38 Correct 252 ms 16152 KB Correct
39 Correct 145 ms 15156 KB Correct
40 Correct 195 ms 14572 KB Correct
41 Correct 84 ms 12016 KB Correct
42 Correct 78 ms 11808 KB Correct
43 Correct 230 ms 16184 KB Correct
44 Correct 205 ms 16016 KB Correct
45 Correct 95 ms 14236 KB Correct
46 Correct 88 ms 14940 KB Correct
47 Correct 91 ms 14164 KB Correct
48 Correct 72 ms 11932 KB Correct
49 Correct 81 ms 12056 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 7712 KB Correct
2 Correct 79 ms 7584 KB Correct
3 Correct 80 ms 7628 KB Correct
4 Correct 82 ms 10840 KB Correct
5 Correct 133 ms 11816 KB Correct
6 Correct 160 ms 12228 KB Correct
7 Correct 80 ms 7512 KB Correct
8 Correct 75 ms 7588 KB Correct
9 Correct 90 ms 7396 KB Correct
10 Correct 76 ms 7508 KB Correct
11 Correct 78 ms 7588 KB Correct
12 Correct 71 ms 7496 KB Correct
13 Correct 70 ms 7356 KB Correct
14 Correct 53 ms 5636 KB Correct
15 Correct 60 ms 5760 KB Correct
16 Correct 80 ms 7500 KB Correct
17 Correct 76 ms 7504 KB Correct
18 Correct 81 ms 7524 KB Correct
19 Correct 84 ms 7524 KB Correct
20 Correct 54 ms 5892 KB Correct
21 Correct 62 ms 5608 KB Correct
22 Correct 59 ms 5708 KB Correct
23 Correct 60 ms 5632 KB Correct
24 Correct 54 ms 5876 KB Correct
25 Correct 65 ms 5532 KB Correct
26 Correct 74 ms 7672 KB Correct
27 Correct 83 ms 7940 KB Correct
28 Correct 78 ms 7836 KB Correct
29 Correct 76 ms 7504 KB Correct
30 Correct 84 ms 7964 KB Correct
31 Correct 84 ms 7580 KB Correct
32 Correct 88 ms 7756 KB Correct
33 Correct 77 ms 7564 KB Correct
34 Correct 82 ms 7772 KB Correct
35 Correct 91 ms 7504 KB Correct
36 Correct 78 ms 7844 KB Correct
37 Correct 83 ms 7692 KB Correct
38 Correct 93 ms 7596 KB Correct
39 Correct 78 ms 7772 KB Correct
40 Correct 75 ms 7696 KB Correct
41 Correct 78 ms 7580 KB Correct
42 Correct 80 ms 7756 KB Correct
43 Correct 73 ms 7796 KB Correct
44 Correct 75 ms 7780 KB Correct
45 Correct 70 ms 7452 KB Correct
46 Correct 97 ms 7660 KB Correct
47 Correct 82 ms 7996 KB Correct
48 Correct 82 ms 7696 KB Correct
49 Correct 83 ms 7988 KB Correct
50 Correct 87 ms 7780 KB Correct
51 Correct 68 ms 7504 KB Correct
52 Correct 98 ms 7512 KB Correct
53 Correct 79 ms 7584 KB Correct
54 Correct 94 ms 7768 KB Correct
55 Correct 80 ms 7748 KB Correct
56 Correct 81 ms 7748 KB Correct
57 Correct 76 ms 7632 KB Correct
58 Correct 77 ms 8100 KB Correct
59 Correct 72 ms 7840 KB Correct
60 Correct 86 ms 7588 KB Correct
61 Correct 75 ms 7504 KB Correct
62 Correct 81 ms 8016 KB Correct
63 Correct 69 ms 7772 KB Correct
64 Correct 71 ms 7744 KB Correct
65 Correct 77 ms 7588 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 764 KB Correct
2 Correct 233 ms 15808 KB Correct
3 Correct 221 ms 15820 KB Correct
4 Correct 106 ms 16004 KB Correct
5 Correct 102 ms 13640 KB Correct
6 Correct 207 ms 15384 KB Correct
7 Correct 80 ms 11924 KB Correct
8 Correct 90 ms 12004 KB Correct
9 Correct 228 ms 16000 KB Correct
10 Correct 215 ms 15852 KB Correct
11 Correct 140 ms 13472 KB Correct
12 Correct 103 ms 14384 KB Correct
13 Correct 268 ms 17392 KB Correct
14 Correct 88 ms 11936 KB Correct
15 Correct 88 ms 11604 KB Correct
16 Correct 204 ms 15804 KB Correct
17 Correct 211 ms 15900 KB Correct
18 Correct 139 ms 13800 KB Correct
19 Correct 105 ms 14860 KB Correct
20 Correct 157 ms 14980 KB Correct
21 Correct 77 ms 11940 KB Correct
22 Correct 80 ms 11800 KB Correct
23 Correct 239 ms 15860 KB Correct
24 Correct 201 ms 16324 KB Correct
25 Correct 102 ms 13668 KB Correct
26 Correct 93 ms 15524 KB Correct
27 Correct 83 ms 13728 KB Correct
28 Correct 83 ms 11792 KB Correct
29 Correct 86 ms 11872 KB Correct
30 Correct 218 ms 16076 KB Correct
31 Correct 228 ms 16032 KB Correct
32 Correct 99 ms 12952 KB Correct
33 Correct 238 ms 16172 KB Correct
34 Correct 242 ms 16064 KB Correct
35 Correct 86 ms 12012 KB Correct
36 Correct 75 ms 11864 KB Correct
37 Correct 208 ms 15828 KB Correct
38 Correct 212 ms 16016 KB Correct
39 Correct 252 ms 16152 KB Correct
40 Correct 145 ms 15156 KB Correct
41 Correct 195 ms 14572 KB Correct
42 Correct 84 ms 12016 KB Correct
43 Correct 78 ms 11808 KB Correct
44 Correct 230 ms 16184 KB Correct
45 Correct 205 ms 16016 KB Correct
46 Correct 95 ms 14236 KB Correct
47 Correct 88 ms 14940 KB Correct
48 Correct 91 ms 14164 KB Correct
49 Correct 72 ms 11932 KB Correct
50 Correct 81 ms 12056 KB Correct
51 Correct 73 ms 7712 KB Correct
52 Correct 79 ms 7584 KB Correct
53 Correct 80 ms 7628 KB Correct
54 Correct 82 ms 10840 KB Correct
55 Correct 133 ms 11816 KB Correct
56 Correct 160 ms 12228 KB Correct
57 Correct 80 ms 7512 KB Correct
58 Correct 75 ms 7588 KB Correct
59 Correct 90 ms 7396 KB Correct
60 Correct 76 ms 7508 KB Correct
61 Correct 78 ms 7588 KB Correct
62 Correct 71 ms 7496 KB Correct
63 Correct 70 ms 7356 KB Correct
64 Correct 53 ms 5636 KB Correct
65 Correct 60 ms 5760 KB Correct
66 Correct 80 ms 7500 KB Correct
67 Correct 76 ms 7504 KB Correct
68 Correct 81 ms 7524 KB Correct
69 Correct 84 ms 7524 KB Correct
70 Correct 54 ms 5892 KB Correct
71 Correct 62 ms 5608 KB Correct
72 Correct 59 ms 5708 KB Correct
73 Correct 60 ms 5632 KB Correct
74 Correct 54 ms 5876 KB Correct
75 Correct 65 ms 5532 KB Correct
76 Correct 74 ms 7672 KB Correct
77 Correct 83 ms 7940 KB Correct
78 Correct 78 ms 7836 KB Correct
79 Correct 76 ms 7504 KB Correct
80 Correct 84 ms 7964 KB Correct
81 Correct 84 ms 7580 KB Correct
82 Correct 88 ms 7756 KB Correct
83 Correct 77 ms 7564 KB Correct
84 Correct 82 ms 7772 KB Correct
85 Correct 91 ms 7504 KB Correct
86 Correct 78 ms 7844 KB Correct
87 Correct 83 ms 7692 KB Correct
88 Correct 93 ms 7596 KB Correct
89 Correct 78 ms 7772 KB Correct
90 Correct 75 ms 7696 KB Correct
91 Correct 78 ms 7580 KB Correct
92 Correct 80 ms 7756 KB Correct
93 Correct 73 ms 7796 KB Correct
94 Correct 75 ms 7780 KB Correct
95 Correct 70 ms 7452 KB Correct
96 Correct 97 ms 7660 KB Correct
97 Correct 82 ms 7996 KB Correct
98 Correct 82 ms 7696 KB Correct
99 Correct 83 ms 7988 KB Correct
100 Correct 87 ms 7780 KB Correct
101 Correct 68 ms 7504 KB Correct
102 Correct 98 ms 7512 KB Correct
103 Correct 79 ms 7584 KB Correct
104 Correct 94 ms 7768 KB Correct
105 Correct 80 ms 7748 KB Correct
106 Correct 81 ms 7748 KB Correct
107 Correct 76 ms 7632 KB Correct
108 Correct 77 ms 8100 KB Correct
109 Correct 72 ms 7840 KB Correct
110 Correct 86 ms 7588 KB Correct
111 Correct 75 ms 7504 KB Correct
112 Correct 81 ms 8016 KB Correct
113 Correct 69 ms 7772 KB Correct
114 Correct 71 ms 7744 KB Correct
115 Correct 77 ms 7588 KB Correct
116 Correct 81 ms 7904 KB Correct
117 Correct 89 ms 8024 KB Correct
118 Correct 86 ms 7840 KB Correct
119 Correct 82 ms 7980 KB Correct
120 Correct 88 ms 7508 KB Correct
121 Correct 82 ms 7836 KB Correct
122 Correct 93 ms 7716 KB Correct
123 Correct 92 ms 11316 KB Correct
124 Correct 129 ms 11720 KB Correct
125 Correct 165 ms 12868 KB Correct
126 Correct 89 ms 7728 KB Correct
127 Correct 75 ms 7440 KB Correct
128 Correct 76 ms 7836 KB Correct
129 Correct 76 ms 7548 KB Correct
130 Correct 77 ms 7516 KB Correct
131 Correct 80 ms 7644 KB Correct
132 Correct 77 ms 7552 KB Correct
133 Correct 67 ms 5668 KB Correct
134 Correct 63 ms 5624 KB Correct
135 Correct 69 ms 7516 KB Correct
136 Correct 80 ms 7516 KB Correct
137 Correct 82 ms 7620 KB Correct
138 Correct 83 ms 7412 KB Correct
139 Correct 53 ms 5640 KB Correct
140 Correct 51 ms 5532 KB Correct
141 Correct 62 ms 5620 KB Correct
142 Correct 55 ms 5796 KB Correct
143 Correct 62 ms 5616 KB Correct
144 Correct 56 ms 5540 KB Correct
145 Correct 72 ms 7580 KB Correct
146 Correct 75 ms 7676 KB Correct
147 Correct 87 ms 7492 KB Correct
148 Correct 69 ms 7692 KB Correct
149 Correct 88 ms 7584 KB Correct
150 Correct 74 ms 7768 KB Correct
151 Correct 86 ms 7780 KB Correct
152 Correct 83 ms 7756 KB Correct
153 Correct 78 ms 7580 KB Correct
154 Correct 68 ms 7764 KB Correct
155 Correct 94 ms 7580 KB Correct
156 Correct 91 ms 7752 KB Correct
157 Correct 86 ms 7580 KB Correct
158 Correct 82 ms 7676 KB Correct
159 Correct 78 ms 7500 KB Correct
160 Correct 78 ms 7516 KB Correct
161 Correct 84 ms 8024 KB Correct
162 Correct 83 ms 7496 KB Correct
163 Correct 82 ms 7836 KB Correct
164 Correct 64 ms 7540 KB Correct
165 Correct 87 ms 7520 KB Correct
166 Correct 95 ms 7844 KB Correct
167 Correct 76 ms 7588 KB Correct
168 Correct 77 ms 7756 KB Correct
169 Correct 72 ms 7604 KB Correct
170 Correct 83 ms 7516 KB Correct
171 Correct 88 ms 8096 KB Correct
172 Correct 82 ms 7496 KB Correct
173 Correct 70 ms 7712 KB Correct
174 Correct 81 ms 7580 KB Correct
175 Correct 68 ms 7884 KB Correct
176 Correct 78 ms 7580 KB Correct
177 Correct 81 ms 7848 KB Correct
178 Correct 86 ms 7828 KB Correct
179 Correct 80 ms 7576 KB Correct
180 Correct 81 ms 7680 KB Correct
181 Correct 77 ms 8144 KB Correct
182 Correct 78 ms 7772 KB Correct
183 Correct 73 ms 7692 KB Correct
184 Correct 82 ms 7496 KB Correct
185 Correct 206 ms 15684 KB Correct
186 Correct 247 ms 16048 KB Correct
187 Correct 120 ms 15948 KB Correct
188 Correct 108 ms 13724 KB Correct
189 Correct 198 ms 14832 KB Correct
190 Correct 86 ms 11932 KB Correct
191 Correct 89 ms 11932 KB Correct
192 Correct 215 ms 15812 KB Correct
193 Correct 218 ms 15748 KB Correct
194 Correct 159 ms 13644 KB Correct
195 Correct 100 ms 14268 KB Correct
196 Correct 277 ms 17032 KB Correct
197 Correct 76 ms 11800 KB Correct
198 Correct 86 ms 11708 KB Correct
199 Correct 210 ms 15912 KB Correct
200 Correct 225 ms 15884 KB Correct
201 Correct 125 ms 13708 KB Correct
202 Correct 108 ms 14836 KB Correct
203 Correct 182 ms 14640 KB Correct
204 Correct 95 ms 11936 KB Correct
205 Correct 87 ms 11868 KB Correct
206 Correct 204 ms 16192 KB Correct
207 Correct 236 ms 15944 KB Correct
208 Correct 99 ms 13660 KB Correct
209 Correct 94 ms 15700 KB Correct
210 Correct 91 ms 13912 KB Correct
211 Correct 83 ms 11868 KB Correct
212 Correct 88 ms 11872 KB Correct
213 Correct 231 ms 15732 KB Correct
214 Correct 211 ms 15792 KB Correct
215 Correct 84 ms 12820 KB Correct
216 Correct 231 ms 16124 KB Correct
217 Correct 243 ms 15768 KB Correct
218 Correct 74 ms 11776 KB Correct
219 Correct 82 ms 11848 KB Correct
220 Correct 200 ms 15952 KB Correct
221 Correct 212 ms 16236 KB Correct
222 Correct 277 ms 16184 KB Correct
223 Correct 153 ms 14668 KB Correct
224 Correct 215 ms 14916 KB Correct
225 Correct 87 ms 12092 KB Correct
226 Correct 83 ms 11932 KB Correct
227 Correct 221 ms 15940 KB Correct
228 Correct 236 ms 16016 KB Correct
229 Correct 90 ms 14236 KB Correct
230 Correct 89 ms 14680 KB Correct
231 Correct 99 ms 13912 KB Correct
232 Correct 83 ms 11940 KB Correct
233 Correct 89 ms 11872 KB Correct
234 Correct 103 ms 11612 KB Correct
235 Correct 104 ms 10588 KB Correct
236 Correct 60 ms 5620 KB Correct
237 Correct 60 ms 5624 KB Correct
238 Correct 55 ms 5680 KB Correct
239 Correct 41 ms 4776 KB Correct
240 Correct 79 ms 7840 KB Correct
241 Correct 80 ms 7512 KB Correct
242 Correct 87 ms 7772 KB Correct
243 Correct 79 ms 7580 KB Correct
244 Correct 80 ms 7504 KB Correct
245 Correct 77 ms 7768 KB Correct
246 Correct 81 ms 7696 KB Correct
247 Correct 76 ms 7580 KB Correct
248 Correct 83 ms 7520 KB Correct
249 Correct 89 ms 7528 KB Correct
250 Correct 74 ms 7584 KB Correct
251 Correct 81 ms 7756 KB Correct
252 Correct 76 ms 7580 KB Correct
253 Correct 89 ms 7764 KB Correct
254 Correct 76 ms 7776 KB Correct
255 Correct 79 ms 7712 KB Correct
256 Correct 81 ms 7584 KB Correct
257 Correct 77 ms 7576 KB Correct
258 Correct 75 ms 7580 KB Correct
259 Correct 79 ms 7580 KB Correct
260 Correct 78 ms 7580 KB Correct
261 Correct 71 ms 7508 KB Correct
262 Correct 77 ms 7584 KB Correct
263 Correct 86 ms 7772 KB Correct
264 Correct 79 ms 7592 KB Correct
265 Correct 56 ms 5640 KB Correct
266 Correct 60 ms 5704 KB Correct
267 Correct 60 ms 5624 KB Correct
268 Correct 55 ms 5644 KB Correct
269 Correct 57 ms 5632 KB Correct
270 Correct 60 ms 5780 KB Correct
271 Correct 53 ms 5544 KB Correct
272 Correct 56 ms 5616 KB Correct
273 Correct 61 ms 5724 KB Correct
274 Correct 61 ms 5636 KB Correct
275 Correct 57 ms 5620 KB Correct
276 Correct 59 ms 5884 KB Correct
277 Correct 54 ms 5624 KB Correct
278 Correct 61 ms 5636 KB Correct
279 Correct 54 ms 5636 KB Correct
280 Correct 89 ms 7836 KB Correct
281 Correct 81 ms 7836 KB Correct
282 Correct 76 ms 8024 KB Correct
283 Correct 75 ms 7580 KB Correct
284 Correct 88 ms 7928 KB Correct
285 Correct 77 ms 8104 KB Correct
286 Correct 83 ms 8036 KB Correct
287 Correct 79 ms 7840 KB Correct
288 Correct 78 ms 7848 KB Correct
289 Correct 72 ms 7940 KB Correct