eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

The Heart of the Country

The Heart of the Country

The nation of Graphia is at war. The neighboring nations have for long watched in jealousy as Graphia erected prosperous cities and connected them with a network of highways. Now they want a piece of the pie. Graphia consists of several cities, connected by highways. Graphian terrain is rough, so the only way to move between the cities is along the highways. Each city has a certain number of troops quartered there. Graphia's military command knows that it will require a certain number of troops, \textbf{K}, to defend any city. They can defend a city with the troops stationed there, supported by the troops in any other city which is directly connected with a highway, with no cities in between. Any troops further away than that simply cannot get there in time. They also know that their enemies will onlyattack one city at a time - so the troops in a city can be used to defend that city, as well as any of its neighbors. However, if a city can't be defended, then the military command must assume that the troops quartered in that city will be captured, and cannot aid in the defense of Graphia. In the case below, suppose \textbf{K} = \textbf{10}. City \textbf{C} might seem well defended, but it will eventually fall. \includegraphics{https://static.e-olymp.com/content/5d/5dfe6d59c8c4f99f1489bf16f7ca64eeb3884aea.jpg} Graphia's leadership wants to identify the Heart of their country - the largest possible group of cities that can mutually defend each other, even if all of the other cities fall. More formally, a city is defensible if it can draw a total of at least \textbf{K} troops from itself, and from cities directly adjacent to it. A set of cities is defensible if every city in it is defensible, using only troops from itself and adjacent cities in that set. The Heart of the country is the largest possible defensible set of cities - that is, no other defensible set of cities has more cities in it. \InputFile There will be several data sets. Each set begins with two integers, \textbf{N} and \textbf{K}, where \textbf{N} is the number of cities (\textbf{3} <= \textbf{N} <= \textbf{1000}), and \textbf{K} is the number of troops required to defend a city. The cities are numbered \textbf{0} through \textbf{N}-\textbf{1}. On the next \textbf{N} lines are descriptions of the cities, starting with city \textbf{0}. Each of the city description lines begins with an integer \textbf{T}, indicating the number of troops quartered in that city (\textbf{0} <= \textbf{T} <= \textbf{10000}). This is followed by an integer \textbf{M}, indicating the number of highways going out of that city, and then \textbf{M} integers, indicating the cities those highways go to. No two highways will go from and to the same cities, so every city in each list will be unique. No highway will loop from a city back to the same city. The highways go both ways, so that if city \textbf{I} is in city \textbf{J}'s list, then it's guaranteed that city \textbf{J} will be in city \textbf{I}'s list in the input. The input will end with a line with two space-separated \textbf{0}'s. \OutputFile For each data set, print two integers on a single line: The number of cities in the heart of the country, and the number of troops in the heart of the country. Print a space between the integers. There should be no blank lines between outputs.
Лимит времени 2 секунды
Лимит использования памяти 64 MiB
Входные данные #1
4 900
100 2 1 2
200 2 0 3
500 2 0 3
1000 2 1 2
4 900
100 3 1 2 3
200 3 0 3 2
500 3 1 3 0
1000 3 2 1 0
0 0
Выходные данные #1
3 1700
4 1800