#include<bits/stdc++.h>
#include "catdog.h"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=int;
const ll maxN=2e5;
const ll inf=1e9;
const ll mod=1e9+7;
ll a[maxN],dp[maxN][3];
vector<ll>g[maxN];
ll ans=0;
void dfs(ll u,ll p=0)
{
dp[u][1]=dp[u][2]=0;
dp[u][a[u]^3]=inf;
for(int v:g[u])
{
if(v!=p)
{
dfs(v,u);
dp[u][1]+=min({dp[v][1],dp[v][2]+1});
dp[u][2]+=min({dp[v][2],dp[v][1]+1});
}
}
}
void initialize(int n,vector<int> A,vector<int>B)
{
for(int i=0;i<n-1;i++)
{
g[A[i]].pb(B[i]);
g[B[i]].pb(A[i]);
}
for(int i=1;i<=n;i++)
{
a[i]=0;
}
}
ll cat(int v)
{
a[v]=1;
ans=0;
dfs(1);
return min({dp[1][1],dp[1][2]});
}
ll dog(int v)
{
a[v]=2;
ans=0;
dfs(1);
return min({dp[1][1],dp[1][2]});;
}
ll neighbor(int v)
{
a[v]=0;
ans=0;
dfs(1);
return min({dp[1][1],dp[1][2]});
}
/*int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
initialize(5,{1,2,2,4},{2,3,4,5});
cat(3),dog(5);
cat(2),dog(1);
cout << dog(1);
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
7 ms |
5052 KB |
Output is correct |
18 |
Correct |
9 ms |
5064 KB |
Output is correct |
19 |
Correct |
5 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
10 ms |
5068 KB |
Output is correct |
24 |
Correct |
8 ms |
5060 KB |
Output is correct |
25 |
Correct |
4 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
5036 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
11 ms |
5116 KB |
Output is correct |
30 |
Correct |
3 ms |
5032 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
4 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
7 ms |
5052 KB |
Output is correct |
18 |
Correct |
9 ms |
5064 KB |
Output is correct |
19 |
Correct |
5 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
10 ms |
5068 KB |
Output is correct |
24 |
Correct |
8 ms |
5060 KB |
Output is correct |
25 |
Correct |
4 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
5036 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
11 ms |
5116 KB |
Output is correct |
30 |
Correct |
3 ms |
5032 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
4 ms |
4948 KB |
Output is correct |
33 |
Execution timed out |
3047 ms |
8644 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |