# 树形dp Strategic game

wa了两次

http://poj.org/problem?id=1463

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MAX=1530;

vector<int> bian[MAX];
int dp[MAX][2],visited[MAX];

void dps(int t)
{
if(visited[t])
return;
visited[t]=1;
dp[t][0]=0;
dp[t][1]=1;
for(int i=0;i<bian[t].size();i++)
{
int tbian=bian[t][i];
if(!visited[tbian])
{
dps(tbian);
dp[t][0]+=dp[tbian][1];
dp[t][1]+=min(dp[tbian][0],dp[tbian][1]);

}
}

}

int main()
{
int n,m,x,y;
int i,j,k;
int root;
while(scanf("%d",&n)==1)
{
root=0;
for(int i=0;i<n;++i)
{
scanf("%d: (%d)",&x,&m);
if(m)
root=x;
while(m--)
{
scanf("%d",&y);
bian[x].push_back(y);
bian[y].push_back(x);
}
}
memset(dp,0,sizeof(dp));
memset(visited,false,sizeof(visited));
dps(root);
for(i=0;i<MAX;i++)
bian[i].clear();
printf("%d\n",min(dp[root][0],dp[root][1]));
}

return 0;
}

04-21 2736
10-31 1414
04-02 4906
04-27 1243
02-23 1340
12-22 3万+
02-11 2865
11-13 1563
04-29 1311
02-23 1216
07-11 3837
08-02 1万+
11-20 6616
12-21 1195
07-22 1149