codeforces 161 D. Distance in Tree(树形dp) 题目链接:http://codeforces.com/problemset/problem/161/D 题意:给出一个树,问树上点到点的距离为k的一共有几个。 一道简单的树形dp,算是一个基础题。 设dp[i][len]表示i为根距离为len的一共有几个点。 一般的树形dp都是先dfs然后再更新dp的值,注意按...
importjava.io.*;importjava.util.*;publicclassMain{staticInputReader in;staticPrintWriter out;publicstaticvoidmain(String[]args)throws IOException{//InputStream ins = new FileInputStream("E:\\rush.txt");InputStream ins=System.in;in=newInputReader(ins);out=newPrintWriter(System.out);//code start...
public void solve(InputReader in,PrintWriter out) { dp = new long[N+10][K+10]; g = new ArrayList[N+10]; for (int i = 1;i<= N;i++) g[i] = new ArrayList(); n = in.nextInt(); k = in.nextInt(); for (int i = 1;i <= n-1;i++) { int x,y; x = in.nextIn...
Hello guys, I was solving this problem (http://codeforces.com/contest/161/problem/D). After trying for sometime , I read the editorial of the problem and I am not being able to understand the meaning of this line. Can anyobdy help me with this? I basically want to understand about ...
Hi, I was trying to solve the question 161D - Distance in Tree but I'm getting WA on test 11 and can't figure out what's wrong. And the editorial is a bit confusing to me. Here is my submission : 85076026 Can anyone suggest what might've gone wrong. Thanks in advance !
This version of the problem differs from the previous one only in the constraint on nn. A tree is a connected undirected graph without cycles. A weighted tree has a weight assigned to each edge. The distance between two vertices is the minimum sum of weights on the path connecting them. ...
The first line contains integer n (2 ≤ n ≤ 300) — amount of cities in Berland. Then there follow n lines with n integer numbers each — the matrix of shortest distances. j-th integer in the i-th row — di, j, the shortest distance between cities i and j. It is ...
1367C-SocialDistance.cpp 1368A-C+eq.cpp 1368B-CodeforcesSubsequences.cpp 1368C-EvenPicture.cpp 1369A-FashionabLee.cpp 1369B-AccurateLee.cpp 1369C-RationalLee.cpp 1370A-1370A-MaximumGCD.cpp 1370B-GCDCompression.cpp 1370C-NumberGame.cpp ...
161D. Distance in Tree.cpp 161D Feb 18, 2018 19D seg+set.cpp 19D segtree+set Mar 12, 2018 19Dsplay.cpp 19D splay tree Mar 13, 2018 1A Theatre Square.cpp 158A 1A 71A Jan 18, 2018 1B Spreadsheets.cpp 912 Feb 7, 2018
It is guaranteed that the given edges form a tree. It is guaranteed that there are no loops and multiple edges in the given edges. Output Print a single integer — the minimum number of edges you have to add in order to make the shortest distance from the vertex 1 1 to any other ...