Compressed Spanning Subtrees

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

For a tree TT consisting of nn vertices numbered from 11 to nn, the compressed spanning subtree S(X)S(X) of a set XX of spanned vertices (vertices that are not in XX are called not spanned) can be defined by the following algorithm:

  1. Assign S(X)TS(X) \leftarrow T;
  2. If there is any not spanned vertex that has exactly one edge incident to it, remove it along with the edge;
  3. Repeat step 22 while its condition stays true;
  4. If there is any not spanned vertex that has exactly two edges incident to it, remove it along with the edges and add a new edge connecting the two remaining endpoints of the removed edges;
  5. Repeat step 44 while its condition stays true.

Formally, S(X)S(X) is the smallest subgraph of TT containing all vertices in XX and then having all other vertices of degree two or less smoothed out.

The tree from test 11, and its compressed spanning subtrees for X=3,4,6X = {3, 4, 6} and for X=2,5,6X = {2, 5, 6}.

You are not given the tree TT. Instead, your task is to find it. You can ask questions of the following form: "How many vertices does the compressed spanning subtree of XX contain?". And since otherwise finding the tree by asking such questions would be impossible, there are no vertices incident to exactly two edges in TT.