E. The Number Games

Codeforces
IDCF980E
Time3000ms
Memory256MB
Difficulty
data structuresgreedytrees
English · Original
Chinese · Translation
Formal · Original
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant. The nation has $n$ districts numbered from $1$ to $n$, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $i$ is equal to $2^i$. This year, the president decided to reduce the costs. He wants to remove $k$ contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts. The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants. Which contestants should the president remove? ## Input The first line of input contains two integers $n$ and $k$ ($1 \leq k < n \leq 10^6$) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively. The next $n-1$ lines each contains two integers $a$ and $b$ ($1 \leq a, b \leq n$, $a \ne b$), that describe a road that connects two different districts $a$ and $b$ in the nation. It is guaranteed that there is exactly one path between every two districts. ## Output Print $k$ space-separated integers: the numbers of the districts of which the contestants should be removed, **in increasing order of district number**. [samples] ## Note In the first sample, the maximum possible total number of fans is $2^2 + 2^5 + 2^6 = 100$. We can achieve it by removing the contestants of the districts 1, 3, and 4.
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant. The nation has $n$ districts numbered from $1$ to $n$, each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $i$ is equal to $2^i$. This year, the president decided to reduce the costs. He wants to remove $k$ contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts. The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants. Which contestants should the president remove? The first line of input contains two integers $n$ and $k$ ($1 lt.eq k < n lt.eq 10^6$) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively. The next $n -1$ lines each contains two integers $a$ and $b$ ($1 lt.eq a, b lt.eq n$, $a != b$), that describe a road that connects two different districts $a$ and $b$ in the nation. It is guaranteed that there is exactly one path between every two districts. Print $k$ space-separated integers: the numbers of the districts of which the contestants should be removed, *in increasing order of district number*. In the first sample, the maximum possible total number of fans is $2^2 + 2^5 + 2^6 = 100$. We can achieve it by removing the contestants of the districts 1, 3, and 4. ## Input The first line of input contains two integers $n$ and $k$ ($1 lt.eq k < n lt.eq 10^6$) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.The next $n -1$ lines each contains two integers $a$ and $b$ ($1 lt.eq a, b lt.eq n$, $a != b$), that describe a road that connects two different districts $a$ and $b$ in the nation. It is guaranteed that there is exactly one path between every two districts. ## Output Print $k$ space-separated integers: the numbers of the districts of which the contestants should be removed, *in increasing order of district number*. [samples] ## Note In the first sample, the maximum possible total number of fans is $2^2 + 2^5 + 2^6 = 100$. We can achieve it by removing the contestants of the districts 1, 3, and 4.
**Definitions** Let $ n \in \mathbb{Z} $ be the number of districts, and $ k \in \mathbb{Z} $ the number of contestants to remove, with $ 1 \le k < n \le 10^6 $. Let $ G = (V, E) $ be a tree with vertex set $ V = \{1, 2, \dots, n\} $, where each vertex $ i \in V $ has weight $ w_i = 2^i $. Let $ R \subseteq V $ be the set of removed districts, with $ |R| = k $. Let $ S = V \setminus R $ be the set of remaining districts. **Constraints** 1. $ G $ is a tree (connected, acyclic, $ |E| = n - 1 $). 2. The subgraph induced by $ S $ must be connected. 3. $ |R| = k $. **Objective** Maximize the total weight of remaining districts: $$ \sum_{i \in S} 2^i $$ Equivalently, minimize the total weight of removed districts: $$ \sum_{i \in R} 2^i $$ subject to the connectivity constraint on $ S $. **Output** Return the set $ R $ of $ k $ districts to remove, sorted in increasing order, such that the induced subgraph on $ V \setminus R $ remains connected and $ \sum_{i \in R} 2^i $ is minimized.
Samples
Input #1
6 3
2 1
2 6
4 2
5 6
2 3
Output #1
1 3 4
Input #2
8 4
2 6
2 7
7 8
1 2
3 1
2 4
7 5
Output #2
1 3 4 5
API Response (JSON)
{
  "problem": {
    "name": "E. The Number Games",
    "description": {
      "content": "The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant. The nation has $n$ districts numbered from $1$ to $n$, each ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF980E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.\n\nThe nation has $n$ districts numbered from $1$ to $n$, each ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.\n\nThe nation has $n$ districts numbered from $1$ to $n$, each ...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of districts, and $ k \\in \\mathbb{Z} $ the number of contestants to remove, with $ 1 \\le k < n \\le 10^6 $.  \nLet $ G = (V, E) $ be a tree with ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments