博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Uva 11183 - Teen Girl Squad (最小树形图)
阅读量:7068 次
发布时间:2019-06-28

本文共 2146 字,大约阅读时间需要 7 分钟。

Problem I

Teen Girl Squad 
Input: Standard Input Output: Standard Output 

You are part of a group of n teenage girls armed with cellphones. You have some news you want to tell everyone in the group. The problem is that no two of you are in the same room, and you must communicate using only cellphones. What's worse is that due to excessive usage, your parents have refused to pay your cellphone bills, so you must distribute the news by calling each other in the cheapest possible way. You will call several of your friends, they will call some of their friends, and so on until everyone in the group hears the news.

Each of you is using a different phone service provider, and you know the price of girl A calling girl B for all possible A and B. Not all of your friends like each other, and some of them will never call people they don't like. Your job is to find the cheapest possible sequence of calls so that the news spreads from you to all n-1 other members of the group.

Input

The first line of input gives the number of cases, (N<150). N test cases follow. Each one starts with two lines containing n (0<=n<=1000)and m (0 <= m <= 40,000). Girls are numbered from 0 to n-1, and you are girl 0. The next m lines will each contain 3 integers, uv and w, meaning that a call from girl u to girl v costs w cents (0 <= w <= 1000). No other calls are possible because of grudges, rivalries and because they are, like, lame. The input file size is around 1200 KB.

Output

For each test case, output one line containing "Case #x:" followed by the cost of the cheapest method of distributing the news. If there is no solution, print "Possums!" instead.

Problem setter: Igor Naverniouk
 
解题思路:最小树形图 模板题
 
1 #include
2 #include
3 #define SIZE 1002 4 #define MAXN 40004 5 6 using namespace std; 7 8 const int INF = 1<<30; 9 int nv, ne, N;10 int vis[SIZE], pre[SIZE], num[SIZE];11 int inLength[SIZE];12 13 struct Edge{14 int u, v, w;15 }edge[MAXN];16 17 bool Traverse(int& res)18 {19 int root = 0;20 while(true)21 {22 for(int i=0; i

 

 

转载于:https://www.cnblogs.com/liaoguifa/p/3218927.html

你可能感兴趣的文章
话里话外:成功CEO的用人之道——按需激励
查看>>
openwrt无线连接互联网的实现原理【1】
查看>>
WPS for Linux(ubuntu)字体配置(字体缺失解决办法)
查看>>
谷歌为Pwnium***竞赛再掷重金 将提供200万美元奖金
查看>>
搭建K8S高可用集群(二进制方式)
查看>>
BSON与JSON的区别
查看>>
我的友情链接
查看>>
Play Framework 模板里使用注入访问数据层
查看>>
Win2008学习(十一),解决Remote App Web访问的证书问题
查看>>
python 实现 自动oa 签到签退 发送邮件提醒
查看>>
今天打开阿里妈妈惊现 ¥50 元佣金
查看>>
Oracle 正确删除archivelog文件
查看>>
微信JS 关闭网页
查看>>
[AAuto]给百宝箱增加娱乐功能
查看>>
Tigase XMPP Server源码部署
查看>>
Intellij IDEA创建Maven Web项目
查看>>
java 7 入门书籍
查看>>
Android Pdf文档的生成、显示与打印
查看>>
SpringMVC三种异常处理方式
查看>>
w命令
查看>>