#include"catdog.h"
#include<iostream>
#include<vector>
#include<algorithm>
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define semicolon ;
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
int n;
vector<int>adj[100010];
int pa[100010];
void dfs(int x)
{
for(int t:adj[x])
{
adj[t].erase(find(all(adj[t]),x));
pa[t]=x;
dfs(t);
}
return;
}
void initialize(int N,vector<int>A,vector<int>B)
{
n=N;
for(int i=0;i<n-1;i++)
adj[A[i]].eb(B[i]),adj[B[i]].eb(A[i]);
dfs(1);
return;
}
int dp[100010][2];
int col[100010];
void calc(int x)
{
dp[x][0]=dp[x][1]=0;
for(int t:adj[x])
{
calc(t);
dp[x][0]+=min(dp[t][0],dp[t][1]+1);
dp[x][1]+=min(dp[t][1],dp[t][0]+1);
}
if(col[x]==1)
dp[x][0]=inf;
if(col[x]==2)
dp[x][1]=inf;
return;
}
int cat(int v)
{
col[v]=1;
calc(1);
return min(dp[1][0],dp[1][1]);
}
int dog(int v)
{
col[v]=2;
calc(1);
return min(dp[1][0],dp[1][1]);
}
int neighbor(int v)
{
col[v]=0;
calc(1);
return min(dp[1][0],dp[1][1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2684 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
6 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
5 ms |
2808 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
5 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2684 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
6 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
5 ms |
2808 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
5 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
11 ms |
2808 KB |
Output is correct |
18 |
Correct |
14 ms |
2808 KB |
Output is correct |
19 |
Correct |
9 ms |
2808 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
6 ms |
2680 KB |
Output is correct |
22 |
Correct |
6 ms |
2680 KB |
Output is correct |
23 |
Correct |
15 ms |
2808 KB |
Output is correct |
24 |
Correct |
13 ms |
2680 KB |
Output is correct |
25 |
Correct |
8 ms |
2680 KB |
Output is correct |
26 |
Correct |
6 ms |
2680 KB |
Output is correct |
27 |
Correct |
16 ms |
2680 KB |
Output is correct |
28 |
Correct |
7 ms |
2808 KB |
Output is correct |
29 |
Correct |
18 ms |
2860 KB |
Output is correct |
30 |
Correct |
6 ms |
2680 KB |
Output is correct |
31 |
Correct |
5 ms |
2808 KB |
Output is correct |
32 |
Correct |
6 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2684 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
6 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
5 ms |
2808 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
5 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
11 ms |
2808 KB |
Output is correct |
18 |
Correct |
14 ms |
2808 KB |
Output is correct |
19 |
Correct |
9 ms |
2808 KB |
Output is correct |
20 |
Correct |
4 ms |
2680 KB |
Output is correct |
21 |
Correct |
6 ms |
2680 KB |
Output is correct |
22 |
Correct |
6 ms |
2680 KB |
Output is correct |
23 |
Correct |
15 ms |
2808 KB |
Output is correct |
24 |
Correct |
13 ms |
2680 KB |
Output is correct |
25 |
Correct |
8 ms |
2680 KB |
Output is correct |
26 |
Correct |
6 ms |
2680 KB |
Output is correct |
27 |
Correct |
16 ms |
2680 KB |
Output is correct |
28 |
Correct |
7 ms |
2808 KB |
Output is correct |
29 |
Correct |
18 ms |
2860 KB |
Output is correct |
30 |
Correct |
6 ms |
2680 KB |
Output is correct |
31 |
Correct |
5 ms |
2808 KB |
Output is correct |
32 |
Correct |
6 ms |
2680 KB |
Output is correct |
33 |
Execution timed out |
3039 ms |
7756 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |