码迷,mamicode.com
首页 > 其他好文 > 详细

(最小生成树) hdu 4263

时间:2015-05-27 22:31:47      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:

Red/Blue Spanning Tree

Time Limit: 10000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 973    Accepted Submission(s): 365


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,tntf) 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
3 3 2 B 1 2 B 2 3 R 3 1 2 1 1 R 1 2 0 0 0
 

 

Sample Output
1 0
 

 

Source
 
 
题意:
 
题目大意: 给出m条边,是否有满足K条蓝色形成的最小生成数; 
思路:根据最小生成树原理;你先把红边放在前面,贪心,求出一个用了k1条蓝边的生成树;再把蓝边放在前面,贪心,求出一个用了k2条蓝边的生成树
    如果满足k1<=k<=k2,则输出1;否则输出0;
 
太水 就不写了额。。。。
 

(最小生成树) hdu 4263

标签:

原文地址:http://www.cnblogs.com/water-full/p/4534431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!