Adrian the Wonder Child
시간 제한2초메모리 제한2048 MB
0과 1로 표시된 간선을 가진 트리에서 최대 m개의 간선 표시를 바꿔, 같은 값이 연속으로 k개 이하인 가장 긴 경로의 길이를 구한다.
문제
Adrian the Wonder Child started coding for his new project a while ago. Each day he pushed exactly one commit on his Git repository, and now it looks like a tree with vertices.
As we all know, Adi has good and bad days (usually one good day followed by ten bad days, but that fact is less important for this problem). So for every node of the tree except the root (initial commit), he labeled the edge to the parent with either or depending on whether he pushed the corresponding commit on a bad day or on a good day.
A path between two nodes in the tree is considered -alternating if it has at most consecutive edges with the same value.
Looking back on what he did in a particular day, Adi can change his mind on whether it was good or bad; thus, he can flip the label of the edge between the corresponding node and its parent.
Given integers and , Adi asks himself what is the longest -alternating path in the tree that can be obtained by flipping the labels of at most edges.
입력
The first line of the input contains three integers: , , and (, and ).
Each of the following lines contains three integers: , , and ( and ) meaning that there is an edge between nodes and with label .
It is guaranteed that the given edges form a tree.
출력
Output a single number representing the size of the longest -alternating path obtained by flipping the label of at most edges.