// ~Be name khoda~ //
#include "catdog.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
int n, catt[maxn5], dogg[maxn5], a[maxn5];
vector <int> adj[maxn5];
void initialize(int N, std::vector<int> A, std::vector<int> B) {
n = N;
for(int i = 0; i < n - 1; i++){
A[i]--; B[i]--;
adj[A[i]].pb(B[i]);
adj[B[i]].pb(A[i]);
}
return;
}
void dfs(int v, int par){
catt[v] = dogg[v] = 0;
for(auto u : adj[v]) if(u != par){
dfs(u, v);
catt[v] += catt[u];
dogg[v] += dogg[u];
}
if(a[v] == 1){
dogg[v] = catt[v] + 1;
}
if(a[v] == 2){
catt[v] = dogg[v] + 1;
}
if(a[v] == 0){
catt[v] = min(catt[v], dogg[v] + 1);
dogg[v] = min(dogg[v], catt[v] + 1);
}
return;
}
int output(){
dfs(0, -1);
return min(catt[0], dogg[0]);
}
int cat(int v) {
v--;
a[v] = 1;
return output();
}
int dog(int v) {
v--;
a[v] = 2;
return output();
}
int neighbor(int v) {
v--;
a[v] = 0;
return output();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
12008 KB |
Output is correct |
3 |
Correct |
6 ms |
12020 KB |
Output is correct |
4 |
Correct |
7 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12008 KB |
Output is correct |
8 |
Correct |
6 ms |
12052 KB |
Output is correct |
9 |
Correct |
6 ms |
11956 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
7 ms |
12060 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
7 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
12008 KB |
Output is correct |
3 |
Correct |
6 ms |
12020 KB |
Output is correct |
4 |
Correct |
7 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12008 KB |
Output is correct |
8 |
Correct |
6 ms |
12052 KB |
Output is correct |
9 |
Correct |
6 ms |
11956 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
7 ms |
12060 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
7 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
11988 KB |
Output is correct |
17 |
Correct |
14 ms |
12116 KB |
Output is correct |
18 |
Correct |
17 ms |
12124 KB |
Output is correct |
19 |
Correct |
13 ms |
12116 KB |
Output is correct |
20 |
Correct |
7 ms |
12116 KB |
Output is correct |
21 |
Correct |
8 ms |
12060 KB |
Output is correct |
22 |
Correct |
8 ms |
11988 KB |
Output is correct |
23 |
Correct |
18 ms |
12032 KB |
Output is correct |
24 |
Correct |
16 ms |
12136 KB |
Output is correct |
25 |
Correct |
10 ms |
12100 KB |
Output is correct |
26 |
Correct |
8 ms |
11988 KB |
Output is correct |
27 |
Correct |
8 ms |
11988 KB |
Output is correct |
28 |
Correct |
11 ms |
12116 KB |
Output is correct |
29 |
Correct |
20 ms |
12188 KB |
Output is correct |
30 |
Correct |
8 ms |
12064 KB |
Output is correct |
31 |
Correct |
7 ms |
12060 KB |
Output is correct |
32 |
Correct |
9 ms |
11984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
12008 KB |
Output is correct |
3 |
Correct |
6 ms |
12020 KB |
Output is correct |
4 |
Correct |
7 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
12008 KB |
Output is correct |
8 |
Correct |
6 ms |
12052 KB |
Output is correct |
9 |
Correct |
6 ms |
11956 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
7 ms |
12060 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
7 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
11988 KB |
Output is correct |
17 |
Correct |
14 ms |
12116 KB |
Output is correct |
18 |
Correct |
17 ms |
12124 KB |
Output is correct |
19 |
Correct |
13 ms |
12116 KB |
Output is correct |
20 |
Correct |
7 ms |
12116 KB |
Output is correct |
21 |
Correct |
8 ms |
12060 KB |
Output is correct |
22 |
Correct |
8 ms |
11988 KB |
Output is correct |
23 |
Correct |
18 ms |
12032 KB |
Output is correct |
24 |
Correct |
16 ms |
12136 KB |
Output is correct |
25 |
Correct |
10 ms |
12100 KB |
Output is correct |
26 |
Correct |
8 ms |
11988 KB |
Output is correct |
27 |
Correct |
8 ms |
11988 KB |
Output is correct |
28 |
Correct |
11 ms |
12116 KB |
Output is correct |
29 |
Correct |
20 ms |
12188 KB |
Output is correct |
30 |
Correct |
8 ms |
12064 KB |
Output is correct |
31 |
Correct |
7 ms |
12060 KB |
Output is correct |
32 |
Correct |
9 ms |
11984 KB |
Output is correct |
33 |
Execution timed out |
3077 ms |
16524 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |