Red/Blue Spanning Tree#3977

Red/Blue Spanning Tree

2 sekunt
128 megabaýt
Kyn

Given an undirected, unweighted, connected graph, where each edge is colored either blue or red, determine whether a spanning tree with exactly blue edges exists.

Giriş

There will be several test cases in the input. Each test case will begin with a line with three integers:

Where (2 \le n \le 1000) is the number of nodes in the graph, (limited by the structure of the graph) is the number of edges in the graph, and (0 \le k < n) is the number of blue edges desired in the spanning tree.

Each of the next lines will contain three elements, describing the edges:

Where is a character, either capital 'R' or capital 'B', indicating the color of the edge, and and are integers (1 \le f, t \le n, t \ne 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 s.

Çykyş

For each test case, output single line, containing if it is possible to build a spanning tree with exactly blue edges, and if it is not possible. Output no extra spaces, and do not separate answers with blank lines.

Mysallar

1-nji mysal

Loading
Loading