# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
161079 | 2019-10-31T13:25:21 Z | Akashi | Mousetrap (CEOI17_mousetrap) | C++14 | 1132 ms | 158688 KB |
#include <bits/stdc++.h> using namespace std; const int lim = 1e6 + 5; int n, t, m; int w[lim], h[lim], TT[lim]; vector <int> v[lim]; void dfs(int nod = t, int papa = 0){ bool frunza = true; int Max = 0, Max2 = 0; for(auto it : v[nod]){ if(papa == it) continue ; frunza = false; TT[it] = nod; w[it] = w[nod]; h[it] = h[nod] + 1; if(nod != t) w[it] = w[it] + (v[nod].size() - 2); dfs(it, nod); if(w[it] > Max) Max2 = Max, Max = w[it]; else if(w[it] > Max2) Max2 = w[it]; } if(frunza) w[nod] = w[nod] + h[nod]; else{ if(Max2 == 0) w[nod] = w[nod] + h[nod] + 1; else w[nod] = Max2; } } inline bool check(int tmp){ int cnt = 0; for(int nod = m, nr = 0, Last = 0; nod != t ; Last = nod, nod = TT[nod], ++nr){ int aux = 0; for(auto it : v[nod]){ if(it == TT[nod] || it == Last) continue ; if(w[it] - h[nod] - (nod != m) + cnt > tmp) ++aux; } cnt = cnt + aux; if(cnt > nr + 1) return 0; } if(cnt > tmp) return 0; return 1; } int main() { // freopen("1.in", "r", stdin); scanf("%d%d%d", &n, &t, &m); int x, y; for(int i = 2; i <= n ; ++i){ scanf("%d%d", &x, &y); v[x].push_back(y); v[y].push_back(x); } dfs(); int st = 0, dr = 2 * n; while(st <= dr){ int mij = (st + dr) / 2; if(check(mij)) dr = mij - 1; else st = mij + 1; } printf("%d", st); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23864 KB | Output is correct |
3 | Correct | 24 ms | 23800 KB | Output is correct |
4 | Correct | 25 ms | 23860 KB | Output is correct |
5 | Correct | 24 ms | 23800 KB | Output is correct |
6 | Correct | 24 ms | 23928 KB | Output is correct |
7 | Correct | 27 ms | 23800 KB | Output is correct |
8 | Correct | 26 ms | 23800 KB | Output is correct |
9 | Correct | 24 ms | 23800 KB | Output is correct |
10 | Correct | 23 ms | 23800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 453 ms | 66908 KB | Output is correct |
2 | Correct | 409 ms | 62584 KB | Output is correct |
3 | Correct | 1051 ms | 68068 KB | Output is correct |
4 | Correct | 496 ms | 46072 KB | Output is correct |
5 | Correct | 1074 ms | 68156 KB | Output is correct |
6 | Correct | 1020 ms | 68156 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23864 KB | Output is correct |
3 | Correct | 24 ms | 23800 KB | Output is correct |
4 | Correct | 25 ms | 23860 KB | Output is correct |
5 | Correct | 24 ms | 23800 KB | Output is correct |
6 | Correct | 24 ms | 23928 KB | Output is correct |
7 | Correct | 27 ms | 23800 KB | Output is correct |
8 | Correct | 26 ms | 23800 KB | Output is correct |
9 | Correct | 24 ms | 23800 KB | Output is correct |
10 | Correct | 23 ms | 23800 KB | Output is correct |
11 | Correct | 24 ms | 23800 KB | Output is correct |
12 | Correct | 24 ms | 23928 KB | Output is correct |
13 | Correct | 24 ms | 23928 KB | Output is correct |
14 | Correct | 24 ms | 23928 KB | Output is correct |
15 | Correct | 25 ms | 23928 KB | Output is correct |
16 | Correct | 24 ms | 23860 KB | Output is correct |
17 | Correct | 25 ms | 23928 KB | Output is correct |
18 | Correct | 25 ms | 23928 KB | Output is correct |
19 | Correct | 24 ms | 23928 KB | Output is correct |
20 | Correct | 24 ms | 23928 KB | Output is correct |
21 | Correct | 27 ms | 23928 KB | Output is correct |
22 | Correct | 24 ms | 23928 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23800 KB | Output is correct |
2 | Correct | 24 ms | 23864 KB | Output is correct |
3 | Correct | 24 ms | 23800 KB | Output is correct |
4 | Correct | 25 ms | 23860 KB | Output is correct |
5 | Correct | 24 ms | 23800 KB | Output is correct |
6 | Correct | 24 ms | 23928 KB | Output is correct |
7 | Correct | 27 ms | 23800 KB | Output is correct |
8 | Correct | 26 ms | 23800 KB | Output is correct |
9 | Correct | 24 ms | 23800 KB | Output is correct |
10 | Correct | 23 ms | 23800 KB | Output is correct |
11 | Correct | 453 ms | 66908 KB | Output is correct |
12 | Correct | 409 ms | 62584 KB | Output is correct |
13 | Correct | 1051 ms | 68068 KB | Output is correct |
14 | Correct | 496 ms | 46072 KB | Output is correct |
15 | Correct | 1074 ms | 68156 KB | Output is correct |
16 | Correct | 1020 ms | 68156 KB | Output is correct |
17 | Correct | 24 ms | 23800 KB | Output is correct |
18 | Correct | 24 ms | 23928 KB | Output is correct |
19 | Correct | 24 ms | 23928 KB | Output is correct |
20 | Correct | 24 ms | 23928 KB | Output is correct |
21 | Correct | 25 ms | 23928 KB | Output is correct |
22 | Correct | 24 ms | 23860 KB | Output is correct |
23 | Correct | 25 ms | 23928 KB | Output is correct |
24 | Correct | 25 ms | 23928 KB | Output is correct |
25 | Correct | 24 ms | 23928 KB | Output is correct |
26 | Correct | 24 ms | 23928 KB | Output is correct |
27 | Correct | 27 ms | 23928 KB | Output is correct |
28 | Correct | 24 ms | 23928 KB | Output is correct |
29 | Correct | 24 ms | 23928 KB | Output is correct |
30 | Correct | 472 ms | 80504 KB | Output is correct |
31 | Correct | 466 ms | 80284 KB | Output is correct |
32 | Correct | 683 ms | 158648 KB | Output is correct |
33 | Correct | 515 ms | 158688 KB | Output is correct |
34 | Correct | 1104 ms | 81480 KB | Output is correct |
35 | Correct | 1081 ms | 81396 KB | Output is correct |
36 | Correct | 1035 ms | 89180 KB | Output is correct |
37 | Correct | 1132 ms | 88912 KB | Output is correct |
38 | Correct | 842 ms | 91896 KB | Output is correct |
39 | Correct | 1028 ms | 91896 KB | Output is correct |
40 | Correct | 845 ms | 91924 KB | Output is correct |