//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-O2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;
int n, dp[N][2], val[N];
vi G[N];
void initialize(int nn, vi A, vi B){
n = nn;
for (int i = 0; i <nn - 1; i++){
G[A[i]].pb(B[i]);
G[B[i]].pb(A[i]);
}
}
int DFS(int v = 1, int p = 0){
if (val[v] == 1) dp[v][0] = 0, dp[v][1] = INF;
else if(val[v] == 2) dp[v][1] = 0, dp[v][0] = INF;
else dp[v][0] = dp[v][1] = 0;
for (auto u:G[v]){
if (u == p) continue;
DFS(u, v);
dp[v][0] += min(dp[u][0], dp[u][1] + 1);
dp[v][1] += min(dp[u][0] + 1, dp[u][1]);
}
}
int cat(int v){
val[v] = 1;
DFS(1, 0);
return min(dp[1][0], dp[1][1]);
}
int dog(int v){
val[v] = 2;
DFS(1, 0);
return min(dp[1][0], dp[1][1]);
}
int neighbor(int v){
val[v] = 0;
DFS(1, 0);
return min(dp[1][0], dp[1][1]);
}
Compilation message
catdog.cpp: In function 'int DFS(int, int)':
catdog.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
7 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
4992 KB |
Output is correct |
11 |
Correct |
7 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
4992 KB |
Output is correct |
13 |
Correct |
7 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
7 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
4992 KB |
Output is correct |
11 |
Correct |
7 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
4992 KB |
Output is correct |
13 |
Correct |
7 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
4992 KB |
Output is correct |
17 |
Correct |
15 ms |
5120 KB |
Output is correct |
18 |
Correct |
19 ms |
5120 KB |
Output is correct |
19 |
Correct |
13 ms |
5120 KB |
Output is correct |
20 |
Correct |
7 ms |
4992 KB |
Output is correct |
21 |
Correct |
9 ms |
5120 KB |
Output is correct |
22 |
Correct |
9 ms |
5120 KB |
Output is correct |
23 |
Correct |
21 ms |
5120 KB |
Output is correct |
24 |
Correct |
17 ms |
5120 KB |
Output is correct |
25 |
Correct |
11 ms |
5120 KB |
Output is correct |
26 |
Correct |
9 ms |
5120 KB |
Output is correct |
27 |
Correct |
10 ms |
5120 KB |
Output is correct |
28 |
Correct |
10 ms |
5120 KB |
Output is correct |
29 |
Correct |
20 ms |
5120 KB |
Output is correct |
30 |
Correct |
10 ms |
5120 KB |
Output is correct |
31 |
Correct |
8 ms |
5120 KB |
Output is correct |
32 |
Correct |
9 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
7 ms |
4992 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
7 ms |
5120 KB |
Output is correct |
10 |
Correct |
7 ms |
4992 KB |
Output is correct |
11 |
Correct |
7 ms |
4992 KB |
Output is correct |
12 |
Correct |
7 ms |
4992 KB |
Output is correct |
13 |
Correct |
7 ms |
4992 KB |
Output is correct |
14 |
Correct |
7 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
8 ms |
4992 KB |
Output is correct |
17 |
Correct |
15 ms |
5120 KB |
Output is correct |
18 |
Correct |
19 ms |
5120 KB |
Output is correct |
19 |
Correct |
13 ms |
5120 KB |
Output is correct |
20 |
Correct |
7 ms |
4992 KB |
Output is correct |
21 |
Correct |
9 ms |
5120 KB |
Output is correct |
22 |
Correct |
9 ms |
5120 KB |
Output is correct |
23 |
Correct |
21 ms |
5120 KB |
Output is correct |
24 |
Correct |
17 ms |
5120 KB |
Output is correct |
25 |
Correct |
11 ms |
5120 KB |
Output is correct |
26 |
Correct |
9 ms |
5120 KB |
Output is correct |
27 |
Correct |
10 ms |
5120 KB |
Output is correct |
28 |
Correct |
10 ms |
5120 KB |
Output is correct |
29 |
Correct |
20 ms |
5120 KB |
Output is correct |
30 |
Correct |
10 ms |
5120 KB |
Output is correct |
31 |
Correct |
8 ms |
5120 KB |
Output is correct |
32 |
Correct |
9 ms |
4992 KB |
Output is correct |
33 |
Execution timed out |
3083 ms |
9704 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |