D. Bear and Tree Jumps A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of n vertices, num…
题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input :standard input output:standard output Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices a…
题目链接:http://codeforces.com/problemset/problem/161/D 题意:给出一个树,问树上点到点的距离为k的一共有几个. 一道简单的树形dp,算是一个基础题. 设dp[i][len]表示i为根距离为len的一共有几个点. 一般的树形dp都是先dfs然后再更新dp的值,注意按这样写就行了.而且一般的树形dp都是设dp[i][k]i为根,k为条件. void dfs(int u , int pre) { int len = vc[u].size(); dp[u]…
题目描述 A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n. L…
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5834 Description Bi Luo is a magic boy, he also has a migic tree, the tree has N nodes , in each node , there is a treasure, it's value is V[i], and for each edge, there is a cost C[i], which means…
Codeforces 280C Game on tree LINK 题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数 #include<bits/stdc++.h> using namespace std; #define N 100010 int n,tot=0,head[N]={0}; struct Edge{int v,nxt;}E[N<<1]; void add(int u,int v){ E[++tot…