#include "catdog.h"
#include <bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
using namespace std;
const int N = 1e5 + 3;
const int inf = 1 << 30;
int n, A[N], p[N], anc[N], d[N];
int dp[N][2];
vector<int> G[N];
struct CD{
void insert(int v, int cd){
}
void erase(int v){
}
} V[N];
void dfs(int v, int par){
for(auto i : G[v]){
if(i != par){
p[i] = v;
anc[i] = (G[v].size() - (v != 1) == 1) ? anc[v] : v;
d[i] = d[v] + 1;
dfs(i, v);
}
}
}
void initialize(int n, vector<int> A, vector<int> B) {
::n = n;
for(int i = 0; i < n - 1; i++){
G[A[i]].pb(B[i]);
G[B[i]].pb(A[i]);
}
dfs(1, -1);
map<int, vector<int>> PC;
for(int i = 1; i <= n; i++){
PC[anc[i]].push_back(i);
}
for(auto& i : PC){
sort(i.se.begin(), i.se.end(), [](int a, int b){
return d[a] < d[b];
});
}
}
void lift(int v){
while(v != 0){
dp[v][0] = dp[v][1] = 0;
for(auto i : G[v]){
if(i != p[v]){
dp[v][0] += min(dp[i][0], dp[i][1] + 1);
dp[v][1] += min(dp[i][1], dp[i][0] + 1);
}
}
if(A[v] == 1) dp[v][1] = inf;
else if(A[v] == 2) dp[v][0] = inf;
v = p[v];
}
}
int cat(int v) {
A[v] = 1;
V[anc[v]].insert(v, 1);
lift(v);
// cout << "c<<<" << endl;
// for(int i = 1; i <= n; i++){
// cout << dp[i][0] << ' ' << dp[i][1] << endl;
// }
return min(dp[1][0], dp[1][1]);
}
int dog(int v) {
A[v] = 2;
V[anc[v]].insert(v, 2);
lift(v);
// cout << "d<<<" << endl;
// for(int i = 1; i <= n; i++){
// cout << dp[i][0] << ' ' << dp[i][1] << endl;
// }
return min(dp[1][0], dp[1][1]);
}
int neighbor(int v) {
A[v] = 0;
V[anc[v]].erase(v);
lift(v);
// cout << "n<<<" << endl;
// for(int i = 1; i <= n; i++){
// cout << dp[i][0] << ' ' << dp[i][1] << endl;
// }
return min(dp[1][0], dp[1][1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2672 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2672 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2676 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2672 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2672 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2676 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
3 ms |
2772 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
2 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2672 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
3 ms |
2680 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2720 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
2 ms |
2772 KB |
Output is correct |
29 |
Correct |
4 ms |
2772 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2680 KB |
Output is correct |
32 |
Correct |
2 ms |
2672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2672 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2672 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2676 KB |
Output is correct |
14 |
Correct |
2 ms |
2676 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
3 ms |
2772 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
2 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2672 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
3 ms |
2680 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2720 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
2 ms |
2772 KB |
Output is correct |
29 |
Correct |
4 ms |
2772 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2680 KB |
Output is correct |
32 |
Correct |
2 ms |
2672 KB |
Output is correct |
33 |
Correct |
175 ms |
9768 KB |
Output is correct |
34 |
Correct |
85 ms |
9904 KB |
Output is correct |
35 |
Correct |
235 ms |
8164 KB |
Output is correct |
36 |
Correct |
321 ms |
14168 KB |
Output is correct |
37 |
Correct |
19 ms |
6092 KB |
Output is correct |
38 |
Correct |
360 ms |
15360 KB |
Output is correct |
39 |
Correct |
344 ms |
15320 KB |
Output is correct |
40 |
Correct |
431 ms |
15896 KB |
Output is correct |
41 |
Correct |
387 ms |
15380 KB |
Output is correct |
42 |
Correct |
489 ms |
15772 KB |
Output is correct |
43 |
Correct |
395 ms |
15388 KB |
Output is correct |
44 |
Correct |
423 ms |
15756 KB |
Output is correct |
45 |
Correct |
559 ms |
15388 KB |
Output is correct |
46 |
Correct |
401 ms |
15420 KB |
Output is correct |
47 |
Correct |
350 ms |
15752 KB |
Output is correct |
48 |
Execution timed out |
3078 ms |
9668 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |