#P10530. Simplified Life Game on a Tree

    ID: 12548 Type: Default 1000ms 256MiB

Simplified Life Game on a Tree

Simplified Life Game on a Tree

You are given a tree with \(n\) nodes and \(n-1\) edges, and an integer \(k\). The tree is provided as an undirected connected acyclic graph (with 1-indexed nodes). In each round, all nodes whose current degree is exactly \(k\) are removed along with all edges incident to them. Here, the degree of a node is defined as the number of edges connecting to it at that point.

The removal in each round happens simultaneously. Formally, each round is as follows:

  • For each remaining node, compute its degree.
  • Mark every node for which the degree is exactly \(k\).
  • Remove all marked nodes and all edges attached to them.

This process repeats for infinitely many rounds until no more nodes with degree exactly \(k\) exist. After the process stops, the remaining nodes (if any) form several connected components. Two nodes belong to the same connected component if they are connected directly or indirectly through remaining edges.

Your task is to determine the number of connected components that remain after the process finishes.

Note: All mathematical formulas are represented in \(\LaTeX\) format.

inputFormat

The first line of input contains two integers \(n\) and \(k\) \( (1 \leq n \leq 10^5,\ 0 \leq k \leq n)\) -- the number of nodes in the tree and the degree condition respectively.

Each of the next \(n-1\) lines contains two integers \(u\) and \(v\) \( (1 \leq u,v \leq n)\) representing an edge between nodes \(u\) and \(v\).

outputFormat

Output a single integer -- the number of connected components remaining after no more removals can be performed.

sample

5 1
1 2
1 3
3 4
3 5
0