#include <bits/stdc++.h>
using
namespace
std;
#define N 20
int
dfs(vector<
bool
> &visited,
int
s,
int
&K,
int
&removals,
vector<
int
> &removed_nodes,
vector<vector<
int
>> &adj)
{
visited[s] =
true
;
int
nodes = 1;
for
(
int
child : adj[s])
{
if
(visited[child])
continue
;
nodes += dfs(visited, child, K,
removals, removed_nodes,
adj);
}
if
(nodes > K)
{
removals++;
removed_nodes.push_back(s);
nodes = 0;
}
return
nodes;
}
void
addEdge(vector<vector<
int
>> &adj,
int
a,
int
b)
{
adj[a].push_back(b);
adj[b].push_back(a);
}
void
findRemovedNodes(vector<
bool
> &visited,
int
K,
int
&removals,
vector<
int
> &removed_nodes,
vector<vector<
int
>> &adj)
{
dfs(visited, 1, K, removals,
removed_nodes, adj);
cout <<
"Number of nodes removed: "
<< removals << endl;
cout <<
"Removed Nodes: "
;
for
(
int
node : removed_nodes)
{
cout << node <<
" "
;
}
}
int
main()
{
vector<
bool
> visited(N);
int
K;
int
removals = 0;
vector<
int
> removed_nodes;
vector<vector<
int
>> adj(N);
addEdge(adj, 1, 2);
addEdge(adj, 1, 3);
addEdge(adj, 2, 4);
addEdge(adj, 2, 5);
addEdge(adj, 3, 6);
K = 3;
findRemovedNodes(visited, K, removals,
removed_nodes, adj);
return
0;
}