제출 #332938

#제출 시각아이디문제언어결과실행 시간메모리
332938YJUCats or Dogs (JOI18_catdog)C++14
38 / 100
3068 ms14296 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef int 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 long long INF=(1LL<<28); #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() long long dp[N][3],col[N]; vector<ll> v[N]; void DFS(ll nd,ll pa){ dp[nd][1]=dp[nd][2]=0; 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]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...