이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "catdog.h"
#include <vector>
using namespace std;
int x,now=1;
bool have1[1000005];
bool have2[1000005];
int vis[5][1000005];
int DP[5][1000005];
vector < int > Next[100005];
int color[1000005];
int N;
void initialize(int N, std::vector<int> A, std::vector<int> B)
{
int i;
::N=N;
for(i=0;i<N-1;i++)
{
Next[A[i]].push_back(B[i]);
Next[B[i]].push_back(A[i]);
}
}
int F(int color,int here,int fa)
{
if(::color[here]!=color&&::color[here]) return 1e9;
if(vis[color][here]==now) return DP[color][here];
vis[color][here]=now;
DP[color][here]=0;
for(auto i:Next[here])
{
if(i==fa) continue;
DP[color][here]+=min(F(color,i,here),F(3-color,i,here)+1);
}
return DP[color][here];
}
int cat(int v)
{
now++;
color[v]=1;
return min(F(1,1,-1),F(2,1,-1));
}
int dog(int v)
{
now++;
color[v]=2;
return min(F(1,1,-1),F(2,1,-1));
}
int neighbor(int v)
{
now++;
color[v]=0;
return min(F(1,1,-1),F(2,1,-1));
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |