#include "catdog.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int MAXN=1005;
int x;
int dp[MAXN][3];
int p[MAXN];
int n;
vector <int> ls[MAXN];
int rek(int node, int fl, int par=0) {
if (p[node] && p[node]!=fl) return INF;
int &ret=dp[node][fl];
if (ret!=-1) return ret;
ret=0;
for (int sus:ls[node]) {
if (sus!=par) ret+=min(rek(sus, fl, node), rek(sus, 3-fl, node)+1);
}
return ret;
}
//prazno=0, cat=1, dog=2
void initialize(int N, std::vector<int> A, std::vector<int> B) {
n=N;
for (int i=0; i<n-1; ++i) ls[A[i]].pb(B[i]), ls[B[i]].pb(A[i]);
}
int solve() {
memset(dp, -1, sizeof dp);
return min(rek(1, 1), rek(1, 2));
}
int cat(int v) {
p[v]=1;
return solve();
}
int dog(int v) {
p[v]=2;
return solve();
}
int neighbor(int v) {
p[v]=0;
return solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
22 ms |
476 KB |
Output is correct |
18 |
Correct |
30 ms |
380 KB |
Output is correct |
19 |
Correct |
14 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
364 KB |
Output is correct |
22 |
Correct |
5 ms |
364 KB |
Output is correct |
23 |
Correct |
31 ms |
492 KB |
Output is correct |
24 |
Correct |
26 ms |
364 KB |
Output is correct |
25 |
Correct |
11 ms |
364 KB |
Output is correct |
26 |
Correct |
5 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
364 KB |
Output is correct |
28 |
Correct |
7 ms |
492 KB |
Output is correct |
29 |
Correct |
38 ms |
492 KB |
Output is correct |
30 |
Correct |
5 ms |
364 KB |
Output is correct |
31 |
Correct |
4 ms |
364 KB |
Output is correct |
32 |
Correct |
8 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
22 ms |
476 KB |
Output is correct |
18 |
Correct |
30 ms |
380 KB |
Output is correct |
19 |
Correct |
14 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
364 KB |
Output is correct |
22 |
Correct |
5 ms |
364 KB |
Output is correct |
23 |
Correct |
31 ms |
492 KB |
Output is correct |
24 |
Correct |
26 ms |
364 KB |
Output is correct |
25 |
Correct |
11 ms |
364 KB |
Output is correct |
26 |
Correct |
5 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
364 KB |
Output is correct |
28 |
Correct |
7 ms |
492 KB |
Output is correct |
29 |
Correct |
38 ms |
492 KB |
Output is correct |
30 |
Correct |
5 ms |
364 KB |
Output is correct |
31 |
Correct |
4 ms |
364 KB |
Output is correct |
32 |
Correct |
8 ms |
364 KB |
Output is correct |
33 |
Runtime error |
40 ms |
4460 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |