Cities | 프로그래밍의 벗 PivotOJ
PivotOJ

Cities

시간 제한: 2000ms메모리 제한: 1024MB출처: Programmeringsolympiaden 2016 — katt1BOJ 21334

문제

In a far away kingdom, there are NN cities numbered between 00 and N1N - 1. The cities are connected by N1N - 1 two-way roads. Each road has the same length, and connects exactly two cities, such that there is a unique path between any pair of cities.

For any two cities AA and BB, denote by L(A,B)L(A, B) the number of roads of this unique path between cities AA and BB. Given an integer KK, for how many pairs of cities A,BA, B is L(A,B)=KL(A, B) = K?

입력

The sample judge reads input in the following format:

  • line 11: N K
  • line 22: F[0] F[1] .. F[N - 2]
  • line 33: T[0] T[1] .. T[N - 2]

출력

The sample judge will write a single line with the return value of paths(N, K, F, T).

예제

예제 1

입력
5 2
0 0 0 3
1 2 4 4
출력
4
코드를 제출하려면 로그인하세요.