이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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<<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()
long long 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]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |