Number of paths

2.4

10 votes
Dynamic Programming, Algorithms, Trees
Problem

You are given a tree with n vertices and k edges. Each edge has a color between 1 and k. For each i, from 1 to k, determine the number of paths (v, u) in the tree with i different colors.

Note: (v,u)(u,v)

Input format

First line: n and k 

Next n1 lines: Each line contains two numbers pi and ci denoting the parent of (i+1)th node and the color of the edge connecting i+1 to pi.

Output format

Print k numbers where the ith number denotes the number of paths containing i different colors.

Constraints

1n1051k51pi<i

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

-

Editor Image

?