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 travelfrom any town to any other town on this network. NetLine has already identified all pairs of townsbetween which a direct link can be constructed. For each such possible link, they know the cost andthe 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 amongthe 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 linksSumMoney = sum of the money spent to construct the chosen linksV = SumTime * SumMoneyTaskFind a list of N-1 links to build, which minimizes the value V.Description of inputThe first line of input contains integers N – the number of towns and M – the number of pairs oftowns which can be connected. The towns are numbered starting from 0 to N-1. Each of the next Mlines contain four integers x, y, t and c – meaning town x can be connected to town y in time t andwith cost c.Description of outputIn 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. Thenext N-1 lines describe the links to be constructed. Each line contains a pair of numbers (x,y) describinga link to be build (which must be among the possible links described in the input file). Thepairs 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 = cExampletimeismoney.in 5 70 1 161 790 2 161 150 3 13 1531 4 142 1832 4 236 803 4 40 2412 1 65 92timeismoney.out
279 501
2 10 30 23 4方案啥的很好解决,就不写了。
和HNOI2014画框有类似的思想。
1 #include2 #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