题目链接 Distance in Tree $k <= 500$ 这个条件十分重要. 设$f[i][j]$为以$i$为子树,所有后代中相对深度为$j$的结点个数. 状态转移的时候,一个结点的信息由他的儿子转移过来. 那么一边进行状态转移,一边统计答案即可. #include <bits/stdc++.h> using namespace std; ][], deep[]; vector <]; int n, k, x, y; long long ans; void dfs(int…
题目链接: http://codeforces.com/contest/161/problem/D D. Distance in Tree time limit per test 3 secondsmemory limit per test 512 megabytes 问题描述 A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is th…
Prime Distance On Tree Problem description. You are given a tree. If we select 2 distinct nodes uniformly at random, what's the probability that the distance between these 2 nodes is a prime number? Input The first line contains a number N: the numbe…
题目描述 Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid if and only if dist(u,v) not exceed k…
D Tree Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others) Total Submission(s): 1687 Accepted Submission(s): 263 Problem Description There is a skyscraping tree standing on the playground of Nanjing University of…