#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
// push_back
inline int read(){
int sum=,x=;
char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')
x=;
ch=getchar();
}
while(ch>=''&&ch<=''){
sum=(sum<<)+(sum<<)+(ch^),ch=getchar();
}
return x?sum:-sum;
}
inline void write(int x){
if(x<)
putchar('-'),x=-x;
if(x>)
write(x/);
putchar(x%+'');
}
int mi(int x,int y){
return x<y?x:y;
}
int ma(int x,int y){
return x>y?x:y;
}
const int M=;
const int inf=0x3f3f3f3f;
vector<int>g[M];
int dp[M][],f[M];
void dfs(int u){
dp[u][]=,dp[u][]=;
for(int i=;i<g[u].size();i++){
int v=g[u][i];
dfs(v);
dp[u][]+=mi(dp[v][],dp[v][]);
dp[u][]+=dp[v][];
}
}
int main(){
char ch,ch1,ch2;
int n;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++)
f[i]=;
for(int i=;i<=n;i++){
int u,k;
scanf("%d:(%d)",&u,&k);
// cout<<k<<endl;
u++;
g[u].clear();
while(k--){
int v=read();
// cout<<"~~"<<v<<endl;
v++;
g[u].push_back(v);
f[v]=u;
// son[u]=v;
}
}
/*for(int i=1;i<=n;i++) dp[i][0]=0,dp[i][1]=1;*/
int root=;
while(f[root])
root=f[root];
//cout<<root<<endl;
dfs(root);
write(mi(dp[root][],dp[root][]));
putchar('\n');
}
return ;
}

poj 1463树形dp 树的最小覆盖的更多相关文章

  1. poj 1463(树形dp)

    题目链接:http://poj.org/problem?id=1463 思路:简单树形dp,如果不选父亲节点,则他的所有的儿子节点都必须选,如果选择了父亲节点,则儿子节点可选,可不选,取较小者. #i ...

  2. Strategic game(POJ 1463 树形DP)

    Strategic game Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 7490   Accepted: 3483 De ...

  3. (探讨贴)POJ 1463 树形DP解法的不正确性

    POJ1463是一个典型的树状DP题. 通常解法如下代码所示: using namespace std; ; ]; int pre[maxn]; int childcnt[maxn]; int n; ...

  4. Fire (poj 2152 树形dp)

    Fire (poj 2152 树形dp) 给定一棵n个结点的树(1<n<=1000).现在要选择某些点,使得整棵树都被覆盖到.当选择第i个点的时候,可以覆盖和它距离在d[i]之内的结点,同 ...

  5. 树形DP+树状数组 HDU 5877 Weak Pair

    //树形DP+树状数组 HDU 5877 Weak Pair // 思路:用树状数组每次加k/a[i],每个节点ans+=Sum(a[i]) 表示每次加大于等于a[i]的值 // 这道题要离散化 #i ...

  6. [HDU 5293]Tree chain problem(树形dp+树链剖分)

    [HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...

  7. POJ 3162.Walking Race 树形dp 树的直径

    Walking Race Time Limit: 10000MS   Memory Limit: 131072K Total Submissions: 4123   Accepted: 1029 Ca ...

  8. POJ 1655.Balancing Act 树形dp 树的重心

    Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14550   Accepted: 6173 De ...

  9. poj 2486( 树形dp)

    题目链接:http://poj.org/problem?id=2486 思路:经典的树形dp,想了好久的状态转移.dp[i][j][0]表示从i出发走了j步最后没有回到i,dp[i][j][1]表示从 ...

随机推荐

  1. java Kafka 简单应用实例

    kafka官方中文文档  http://kafka.apachecn.org/ java Kafka 简单应用实例  下面是Linux下的单机模式:https://blog.csdn.net/fct2 ...

  2. Codeforces 1296E1 - String Coloring (easy version)

    题目大意: 给定一段长度为n的字符串s 你需要给每个字符进行涂色,然后相邻的不同色的字符可以进行交换 需要保证涂色后能通过相邻交换把这个字符串按照字典序排序(a~z) 你只有两种颜色可以用来涂 问是否 ...

  3. 51nod1007:正整数分组 DP

    1007 正整数分组 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 ...

  4. POJ 1006:Biorhythms 中国剩余定理

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 121194   Accepted: 38157 Des ...

  5. For循环的几个练习

    1.括号里面只能放加或减,如果要使等式成立,括号里面应该放什么运算符12()34()56()78()9 = 59 2.蓝球弹起的高度篮球从10米高的地方落下,每次弹起的高度是原来的0.3倍,问弹跳10 ...

  6. Python Learning Day1

    字符串的操作 # 字符串的操作 str1 = 'my name is xxx, my age is 18.' # 优先掌握的操作: # 1.按索引取值(正向取+反向取) :只能取 print(str1 ...

  7. 移动端 之 触摸事件、Tap事件和swipe事件

    触摸事件 touch是一个事件组,意思不止一个事件,是移动端滑动事件组,touchstart touchmove touchend touchcancel touchstart 当刚刚触摸屏幕的时候触 ...

  8. PAT Advanced 1123 Is It a Complete AVL Tree (30) [AVL树]

    题目 An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child ...

  9. atan2&sin

    //弧度转化角度:弧度*180/PI //角度转化弧度:角度*PI/180 #include <math.h> #include <stdio.h> const double ...

  10. 为什么常用 Map<> map = new HashMap()

    在初学Java的时候,经常能看到教材上的写法,使用了接口Map来引用一个map,而不是它的具体实现,那么这样做的好处是什么呢? <Effective Java>第52条:通过接口引用对象 ...