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

Red/Blue Spanning Tree

Red/Blue Spanning Tree

Given an undirected, unweighted, connected graph, where each edge is colored either blue or red, determine whether a spanning tree with exactly \textbf{k} blue edges exists. \InputFile There will be several test cases in the input. Each test case will begin with a line with three integers: \textbf{n m k} Where \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{1000}) is the number of nodes in the graph, \textbf{m} (limited by the structure of the graph) is the number of edges in the graph, and \textbf{k} (\textbf{0} ≤ \textbf{k} < \textbf{n}) is the number of blue edges desired in the spanning tree. Each of the next \textbf{m} lines will contain three elements, describing the edges: \textbf{c f t} Where \textbf{c} is a character, either capital '\textbf{R}' or capital '\textbf{B}', indicating the color of the edge, and \textbf{f} and \textbf{t} are integers (\textbf{1} ≤\textbf{f}, \textbf{t} ≤ \textbf{n}, \textbf{t} ≠ \textbf{f}) indicating the nodes that edge goes from and to. The graph is guaranteed to be connected, and there is guaranteed to be at most one edge between any pair of nodes. The input will end with a line with three \textbf{0}s. \OutputFile For each test case, output single line, containing \textbf{1} if it is possible to build a spanning tree with exactly \textbf{k} blue edges, and \textbf{0} if it is not possible. Output no extra spaces, and do not separate answers with blank lines.
Лимит времени 2 секунды
Лимит использования памяти 128 MiB
Входные данные #1
3 3 2
B 1 2
B 2 3
R 3 1
2 1 1
R 1 2
0 0 0
Выходные данные #1
1
0
Источник The University of Chicago Invitational Programming Contest 2012 15 April 2012