# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
332933 | YJU | Cats or Dogs (JOI18_catdog) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=4e5+5;
const ll K=350;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll dp[N][3],col[N];
vector<ll> v[N];
void DFS(ll nd,ll pa){
for(auto i:v[nd]){
if(i==pa)continue;
DFS(i,nd);
dp[nd][1]+=min(dp[i][1],dp[i][2]+1);
dp[nd][2]+=min(dp[i][2],dp[i][1]+1);
}
if(col[nd]){dp[nd][3-col[nd]]=INF;}
}
void initialize(ll n,vector<ll> a,vector<ll> b){
REP(i,n-1)v[a[i]].pb(b[i]),v[b[i]].pb(a[i]);
}
ll cat(ll id){
col[id]=1;
DFS(1,0);
return min(dp[1][1],dp[1][2]);
}
ll dog(ll id){
col[id]=2;
DFS(1,0);
return min(dp[1][1],dp[1][2]);
}
ll neighbor(ll id){
col[id]=0;
DFS(1,0);
return min(dp[1][1],dp[1][2]);
}