#include "catdog.h"
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ldb long double
#define db double
#define fin(x) freopen(x,"r",stdin)
#define fout(x) freopen(x,"w",stdout)
#define fo(i,l,r) for(int i=(l);i<=(r);i++)
#define foi(i,l,r) for(int i=(l);i>=(r);i--)
#define el cout<<'\n';
#define cel cerr<<'\n';
#define all(x) x.begin(),x.end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define gb(x,i) (((x)>>(i))&1)
#define mask(i) (1LL<<(i))
#define TIME (1.0 * clock()/CLOCKS_PER_SEC)
using namespace std;
const int N=1e5+5;
const int bl=60;
const ll base=1e9+7;
const ll inf=1e9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll l,ll r)
{
return l+(1ll*rng()*rng()%(r-l+1)+(r-l+1))%(r-l+1);
}
template<class X,class Y>bool maximize(X &a,Y b)
{
if(a<b) return a=b,true;
return false;
}
template<class X,class Y>bool minimize(X &a, Y b)
{
if(a>b) return a=b,true;
return false;
}
void add(auto &a,auto b)
{
a+=b;
if(a>=base) a-=base;
if(a<0) a+=base;
}
vector<int>g[N];
int c[N],dp[N][2];
void dfs(int u,int p)
{
if(!~c[u]) dp[u][0]=dp[u][1]=0;
else dp[u][c[u]^1]=1e9,dp[u][c[u]]=0;
for(int v:g[u]) if(v!=p)
{
dfs(v,u);
fo(i,0,1) if(dp[u][i]!=1e9) dp[u][i]+=min(dp[v][i],dp[v][i^1]+1);
}
}
int cat(int u)
{
c[u]=0;
dfs(1,0);
return min(dp[1][0],dp[1][1]);
}
int dog(int u)
{
c[u]=1;
dfs(1,0);
return min(dp[1][0],dp[1][1]);
}
int neighbor(int u)
{
c[u]=-1;
dfs(1,0);
return min(dp[1][0],dp[1][1]);
}
void initialize(int n,vector<int>a,vector<int>b)
{
fo(i,0,n-2) g[a[i]].pb(b[i]),g[b[i]].pb(a[i]);
fo(i,1,n) c[i]=-1;
}
//int main()
//{
// #define task "o"
// if(fopen(task".inp","r"))
// {
// fin(task".inp");
// //fout(task".out");
// }
// srand(time(NULL));
// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// int n;
// cin>>n;
// vector<int>a(n-1),b(n-1);
// fo(i,0,n-2) cin>>a[i]>>b[i];
// initialize(n,a,b);
// int q;
// cin>>q;
// while(q--)
// {
// int c,u;
// cin>>c>>u;
// if(c==0) cout<<cat(u),el
// else if(c==1) cout<<dog(u),el
// else cout<<neighbor(u),el
// }
// cerr<<"Time elapsed: "<<TIME<<" s.\n";
//}
Compilation message
catdog.cpp:42:10: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
42 | void add(auto &a,auto b)
| ^~~~
catdog.cpp:42:18: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
42 | void add(auto &a,auto b)
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3676 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
3676 KB |
Output is correct |
5 |
Correct |
1 ms |
3676 KB |
Output is correct |
6 |
Correct |
1 ms |
3676 KB |
Output is correct |
7 |
Correct |
1 ms |
3676 KB |
Output is correct |
8 |
Correct |
1 ms |
3676 KB |
Output is correct |
9 |
Correct |
1 ms |
3676 KB |
Output is correct |
10 |
Correct |
1 ms |
3676 KB |
Output is correct |
11 |
Correct |
1 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
3676 KB |
Output is correct |
13 |
Correct |
2 ms |
3928 KB |
Output is correct |
14 |
Correct |
1 ms |
3676 KB |
Output is correct |
15 |
Correct |
1 ms |
3676 KB |
Output is correct |
16 |
Correct |
1 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3676 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
3676 KB |
Output is correct |
5 |
Correct |
1 ms |
3676 KB |
Output is correct |
6 |
Correct |
1 ms |
3676 KB |
Output is correct |
7 |
Correct |
1 ms |
3676 KB |
Output is correct |
8 |
Correct |
1 ms |
3676 KB |
Output is correct |
9 |
Correct |
1 ms |
3676 KB |
Output is correct |
10 |
Correct |
1 ms |
3676 KB |
Output is correct |
11 |
Correct |
1 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
3676 KB |
Output is correct |
13 |
Correct |
2 ms |
3928 KB |
Output is correct |
14 |
Correct |
1 ms |
3676 KB |
Output is correct |
15 |
Correct |
1 ms |
3676 KB |
Output is correct |
16 |
Correct |
1 ms |
3676 KB |
Output is correct |
17 |
Correct |
9 ms |
3676 KB |
Output is correct |
18 |
Correct |
8 ms |
3864 KB |
Output is correct |
19 |
Correct |
5 ms |
3796 KB |
Output is correct |
20 |
Correct |
1 ms |
3796 KB |
Output is correct |
21 |
Correct |
2 ms |
3672 KB |
Output is correct |
22 |
Correct |
2 ms |
3676 KB |
Output is correct |
23 |
Correct |
9 ms |
3804 KB |
Output is correct |
24 |
Correct |
8 ms |
3672 KB |
Output is correct |
25 |
Correct |
4 ms |
3828 KB |
Output is correct |
26 |
Correct |
2 ms |
3676 KB |
Output is correct |
27 |
Correct |
2 ms |
3676 KB |
Output is correct |
28 |
Correct |
3 ms |
3676 KB |
Output is correct |
29 |
Correct |
10 ms |
3904 KB |
Output is correct |
30 |
Correct |
2 ms |
3796 KB |
Output is correct |
31 |
Correct |
2 ms |
3676 KB |
Output is correct |
32 |
Correct |
3 ms |
3796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3676 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
3676 KB |
Output is correct |
5 |
Correct |
1 ms |
3676 KB |
Output is correct |
6 |
Correct |
1 ms |
3676 KB |
Output is correct |
7 |
Correct |
1 ms |
3676 KB |
Output is correct |
8 |
Correct |
1 ms |
3676 KB |
Output is correct |
9 |
Correct |
1 ms |
3676 KB |
Output is correct |
10 |
Correct |
1 ms |
3676 KB |
Output is correct |
11 |
Correct |
1 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
3676 KB |
Output is correct |
13 |
Correct |
2 ms |
3928 KB |
Output is correct |
14 |
Correct |
1 ms |
3676 KB |
Output is correct |
15 |
Correct |
1 ms |
3676 KB |
Output is correct |
16 |
Correct |
1 ms |
3676 KB |
Output is correct |
17 |
Correct |
9 ms |
3676 KB |
Output is correct |
18 |
Correct |
8 ms |
3864 KB |
Output is correct |
19 |
Correct |
5 ms |
3796 KB |
Output is correct |
20 |
Correct |
1 ms |
3796 KB |
Output is correct |
21 |
Correct |
2 ms |
3672 KB |
Output is correct |
22 |
Correct |
2 ms |
3676 KB |
Output is correct |
23 |
Correct |
9 ms |
3804 KB |
Output is correct |
24 |
Correct |
8 ms |
3672 KB |
Output is correct |
25 |
Correct |
4 ms |
3828 KB |
Output is correct |
26 |
Correct |
2 ms |
3676 KB |
Output is correct |
27 |
Correct |
2 ms |
3676 KB |
Output is correct |
28 |
Correct |
3 ms |
3676 KB |
Output is correct |
29 |
Correct |
10 ms |
3904 KB |
Output is correct |
30 |
Correct |
2 ms |
3796 KB |
Output is correct |
31 |
Correct |
2 ms |
3676 KB |
Output is correct |
32 |
Correct |
3 ms |
3796 KB |
Output is correct |
33 |
Execution timed out |
3054 ms |
7884 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |