# Description

Bob enjoys playing computer games, especially strategic games, but
sometimes he cannot find the solution fast enough and then he is very
sad. Now he has the following problem. He must defend a medieval city,
the roads of which form a tree. He has to put the minimum number of
soldiers on the nodes so that they can observe all the edges. Can you
help him?

Your program should find the minimum number of soldiers that Bob has
to put for a given tree.

For example for the tree:

the solution is one soldier ( at the node 1).

# Input

The input contains several data sets in text format. Each data set
represents a tree with the following description:

the number of nodes the description of each node in the following
node_identifier:(0)

The node identifiers are integer numbers between 0 and n-1, for n
nodes (0 < n <= 1500);the number_of_roads in each line of input will
no more than 10. Every edge appears only once in the input data.

# Output

The output should be printed on the standard output. For each given
input data set, print one integer number in a single line that gives
the result (the minimum number of soldiers). An example is given in
the following:

# Sample Input

4
0:(1) 1
1:(2) 2 3
2:(0)
3:(0)
5
3:(3) 1 4 2
1:(1) 0
2:(0)
0:(0)
4:(0)


# Sample Output

1
2


# 思路

• dp[i]为这个不放置士兵所取得的最小值
• dp[i]为这个点放置士兵所取得的最小值:

dp[u]+=min(dp[v],dp[v]);//这一点放
dp[u]+=dp[v];//这一点不放


# 代码

#include <cstdio>
#include <cstring>
#include <cctype>
#include <stdlib.h>
#include <string>
#include <map>
#include <iostream>
#include <stack>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
const int N=2000+20;
int n;
int dp[N],fa[N],root;
vector<int>G[N];
void dfs(int u)
{
dp[u]=1;
for(int i=0; i<(int)G[u].size(); i++)
{
int v=G[u][i];
dfs(v);
dp[u]+=min(dp[v],dp[v]);//这一点放
dp[u]+=dp[v];//这一点不放
}
}

int main()
{
int u,v,m;
while(~scanf("%d",&n))
{
mem(fa,-1);
mem(G,0);
mem(dp,0);
for(int i=1; i<=n; i++)
{
scanf("%d:(%d)",&u,&m);
while(m--)
{
scanf("%d",&v);
G[u].push_back(v);
fa[v]=u;
root=v;
}
}
while(fa[root]!=-1)
root=fa[root];
dfs(root);
printf("%d\n",min(dp[root],dp[root]));
}
return 0;
}



10-06 75                                                                  11-23 336
06-11 264
07-15 231
07-30 47
07-23 147
12-30 354
08-04 45
09-02 32
08-20
03-30
01-05 2万+
01-12 4263
09-18
01-12 2806
01-27