博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
树(最小乘积生成树,克鲁斯卡尔算法):BOI timeismoney
阅读量:5306 次
发布时间:2019-06-14

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

The NetLine company wants to offer broadband internet to N towns. For this, it suffices to construct

a network of N-1 broadband links between the towns, with the property that a message can travel
from any town to any other town on this network. NetLine has already identified all pairs of towns
between which a direct link can be constructed. For each such possible link, they know the cost and
the time it would take to construct the link.
The company is interested in minimizing both the total amount of time (links are built one at a time)
and the total amount of money spent to build the entire network. Since they couldn’t decide among
the two criteria, they decided to use the following formula to evaluate the value of a network:
SumTime = sum of times spent to construct the chosen links
SumMoney = sum of the money spent to construct the chosen links
V = SumTime * SumMoney
Task
Find a list of N-1 links to build, which minimizes the value V.
Description of input
The first line of input contains integers N – the number of towns and M – the number of pairs of
towns which can be connected. The towns are numbered starting from 0 to N-1. Each of the next M
lines contain four integers x, y, t and c – meaning town x can be connected to town y in time t and
with cost c.
Description of output
In the first line of output print two numbers: the total time (SumTime) and total money (Sum-
Money) used in the optimal solution (the one with minimal value V), separated by one space. The
next N-1 lines describe the links to be constructed. Each line contains a pair of numbers (x,y) describing
a link to be build (which must be among the possible links described in the input file). The
pairs can be printed out in any order. When multiple solutions exist, you may print any of them.

Constraints

· 1 ≤ N ≤ 200

· 1 ≤ M ≤ 10 000
· 0 ≤ x,y ≤ N-1
· 1 ≤ t,c ≤ 255
· One test has M = N - 1
· 40% of the tests will have for each possible link t = c
Example
timeismoney.in
5 7
0 1 161 79
0 2 161 15
0 3 13 153
1 4 142 183
2 4 236 80
3 4 40 241
2 1 65 92

timeismoney.out

279 501

2 1
0 3
0 2
3 4

  方案啥的很好解决,就不写了。

  和HNOI2014画框有类似的思想。

1 #include 
2 #include
3 #include
4 using namespace std; 5 const int maxn=210; 6 const int maxm=10010; 7 int fa[maxn],a[maxm],b[maxm]; 8 int u[maxm],v[maxm],n,m; 9 10 struct Node{11 int x,y,z,id;12 Node(int a=0,int b=0,int c=0,int d=0){13 x=a;y=b;z=c;id=d;14 }15 friend bool operator <(Node a,Node b){16 return a.z

 

转载于:https://www.cnblogs.com/TenderRun/p/5700737.html

你可能感兴趣的文章
以最小代价解决同一apk不同资源定制共存问题
查看>>
第四代iPhone电池仍然不可以更换(转)
查看>>
ibatis中的符号#跟$区别
查看>>
QComboBox设置item height(行高)
查看>>
内存原理与PHP的执行过程
查看>>
P3175 [HAOI2015]按位或
查看>>
【HDU5909】Tree Cutting(FWT)
查看>>
多边形区域填充算法--扫描线填充算法(有序边表法) 有代码
查看>>
北京郊区房租面临下调压力 平均单位租金36.2元/平
查看>>
linux programing
查看>>
移动端H5实现图片上传
查看>>
House Robber
查看>>
C#基础之if语句习题
查看>>
ios推送-B/S架构-socket
查看>>
UVALive 4426 Blast the Enemy! 计算几何求重心
查看>>
结对编程收获
查看>>
【技术案例】双目摄像头数据采集
查看>>
PHPStorm 批量选择,多光标同时编辑相同的内容
查看>>
数据库复习总结(3)-创建数据库、表、以及数据类型的介绍
查看>>
列表与导航,内联
查看>>