|
||||||||||
Red/Blue Spanning TreeTime Limit: 10000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1292 Accepted Submission(s): 519 Problem Description Given an undirected, unweighted, connected graph, where each edge is colored either blue or red, determine whether a spanning tree with exactly k blue edges exists. Input There will be several test cases in the input. Each test case will begin with a line with three integers: n m k Where n (2¡Ün¡Ü1,000) is the number of nodes in the graph, m (limited by the structure of the graph) is the number of edges in the graph, and k (0¡Ük<n) is the number of blue edges desired in the spanning tree. Each of the next m lines will contain three elements, describing the edges: c f t Where c is a character, either capital ¡®R¡¯ or capital ¡®B¡¯, indicating the color of the edge, and f and t are integers (1¡Üf,t¡Ün, t¡Ù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 0s. Output For each test case, output single line, containing 1 if it is possible to build a spanning tree with exactly k blue edges, and 0 if it is not possible. Output no extra spaces, and do not separate answers with blank lines. Sample Input
Sample Output
Source | ||||||||||
|