Submission #557851

# Submission time Handle Problem Language Result Execution time Memory
557851 2022-05-06T07:10:02 Z Koosha_mv Cats or Dogs (JOI18_catdog) C++14
38 / 100
3000 ms 28196 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
//#include "catdog.h"

const int N=1e6+99;

int n,ans,a[N],dp[N];
vector<int> g[N];

void initialize(int _n,vector<int> A,vector<int> B){
	n=_n;
	f(i,0,n-1) g[A[i]].pb(B[i]),g[B[i]].pb(A[i]);		
}
void dfs1(int u,int p){
	int cnt1=0,cnt2=0;
	dp[u]=0;
	for(auto v : g[u]){
		if(v==p) continue ;
		dfs1(v,u);
		cnt1+=(dp[v]==1);
		cnt2+=(dp[v]==2);
	}
	if(a[u]==0){
		ans+=min(cnt1,cnt2);
		if(cnt1>cnt2) dp[u]=1;
		if(cnt2>cnt1) dp[u]=2;
	}
	if(a[u]==1){
		ans+=cnt2;
		dp[u]=1;
	}
	if(a[u]==2){
		ans+=cnt1;
		dp[u]=2;
	}
}
int solve(){
	ans=0;
	dfs1(1,1);
	return ans;
}
int cat(int u){
	a[u]=1;	
	return solve();
}
int dog(int u){
	a[u]=2;
	return solve();
}
int neighbor(int u){
	a[u]=0;
	return solve();
}
/*
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	vector<int> A,B;
	int n,q;
	cin>>n;
	f(i,1,n){
		int u,v;
		cin>>u>>v;
		A.pb(u);
		B.pb(v);
	}
	initialize(n,A,B);
	cin>>q;
	while(q--){
		int t,u;
		cin>>t>>u;
		if(t==1) cout<<cat(u)<<endl;
		if(t==2) cout<<dog(u)<<endl;
		if(t==3) cout<<neighbor(u)<<endl;
	}
}*/
/*
5
1 2
2 3
2 4
4 5
3
1 3
2 5
2 1

5
1 2
2 3
2 4
4 5
5
1 3
2 5
1 2
2 1
3 2
*/
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 15 ms 23796 KB Output is correct
3 Correct 15 ms 23764 KB Output is correct
4 Correct 13 ms 23748 KB Output is correct
5 Correct 13 ms 23796 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23812 KB Output is correct
10 Correct 12 ms 23796 KB Output is correct
11 Correct 13 ms 23804 KB Output is correct
12 Correct 13 ms 23764 KB Output is correct
13 Correct 17 ms 23800 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
15 Correct 13 ms 23808 KB Output is correct
16 Correct 12 ms 23796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 15 ms 23796 KB Output is correct
3 Correct 15 ms 23764 KB Output is correct
4 Correct 13 ms 23748 KB Output is correct
5 Correct 13 ms 23796 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23812 KB Output is correct
10 Correct 12 ms 23796 KB Output is correct
11 Correct 13 ms 23804 KB Output is correct
12 Correct 13 ms 23764 KB Output is correct
13 Correct 17 ms 23800 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
15 Correct 13 ms 23808 KB Output is correct
16 Correct 12 ms 23796 KB Output is correct
17 Correct 22 ms 23764 KB Output is correct
18 Correct 25 ms 23780 KB Output is correct
19 Correct 17 ms 23764 KB Output is correct
20 Correct 14 ms 23764 KB Output is correct
21 Correct 17 ms 23800 KB Output is correct
22 Correct 15 ms 23724 KB Output is correct
23 Correct 26 ms 23788 KB Output is correct
24 Correct 23 ms 23872 KB Output is correct
25 Correct 16 ms 23824 KB Output is correct
26 Correct 14 ms 23764 KB Output is correct
27 Correct 14 ms 23764 KB Output is correct
28 Correct 14 ms 23892 KB Output is correct
29 Correct 25 ms 23804 KB Output is correct
30 Correct 13 ms 23764 KB Output is correct
31 Correct 14 ms 23804 KB Output is correct
32 Correct 15 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 15 ms 23796 KB Output is correct
3 Correct 15 ms 23764 KB Output is correct
4 Correct 13 ms 23748 KB Output is correct
5 Correct 13 ms 23796 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 15 ms 23804 KB Output is correct
9 Correct 14 ms 23812 KB Output is correct
10 Correct 12 ms 23796 KB Output is correct
11 Correct 13 ms 23804 KB Output is correct
12 Correct 13 ms 23764 KB Output is correct
13 Correct 17 ms 23800 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
15 Correct 13 ms 23808 KB Output is correct
16 Correct 12 ms 23796 KB Output is correct
17 Correct 22 ms 23764 KB Output is correct
18 Correct 25 ms 23780 KB Output is correct
19 Correct 17 ms 23764 KB Output is correct
20 Correct 14 ms 23764 KB Output is correct
21 Correct 17 ms 23800 KB Output is correct
22 Correct 15 ms 23724 KB Output is correct
23 Correct 26 ms 23788 KB Output is correct
24 Correct 23 ms 23872 KB Output is correct
25 Correct 16 ms 23824 KB Output is correct
26 Correct 14 ms 23764 KB Output is correct
27 Correct 14 ms 23764 KB Output is correct
28 Correct 14 ms 23892 KB Output is correct
29 Correct 25 ms 23804 KB Output is correct
30 Correct 13 ms 23764 KB Output is correct
31 Correct 14 ms 23804 KB Output is correct
32 Correct 15 ms 23800 KB Output is correct
33 Execution timed out 3051 ms 28196 KB Time limit exceeded
34 Halted 0 ms 0 KB -