zoukankan      html  css  js  c++  java
  • 1083. [SCOI2005]繁忙的都市【最小生成树】

    Description

      城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造。城市C的道
    路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条道路相连
    接。这些道路是双向的,且把所有的交叉路口直接或间接的连接起来了。每条道路都有一个分值,分值越小表示这
    个道路越繁忙,越需要进行改造。但是市政府的资金有限,市长希望进行改造的道路越少越好,于是他提出下面的
    要求: 1. 改造的那些道路能够把所有的交叉路口直接或间接的连通起来。 2. 在满足要求1的情况下,改造的
    道路尽量少。 3. 在满足要求1、2的情况下,改造的那些道路中分值最大的道路分值尽量小。任务:作为市规划
    局的你,应当作出最佳的决策,选择那些道路应当被修建。

    Input

      第一行有两个整数n,m表示城市有n个交叉路口,m条道路。接下来m行是对每条道路的描述,u, v, c表示交叉
    路口u和v之间有道路相连,分值为c。(1≤n≤300,1≤c≤10000)

    Output

      两个整数s, max,表示你选出了几条道路,分值最大的那条道路的分值是多少。

    Sample Input

    4 5
    1 2 3
    1 4 5
    2 4 7
    2 3 6
    3 4 8

    Sample Output

    3 6

    最小生成树模板

     1 #include<iostream>
     2 #include<algorithm>
     3 using namespace std;
     4 
     5 int father[1001],n,m,k,i,ans;
     6 
     7 struct node
     8 {
     9     int x,y,cost;
    10 }sugar[10001]; 
    11 
    12 bool cmp(node a,node b)
    13 {
    14     return a.cost<b.cost;
    15 }
    16 
    17 int find(int x)
    18 {
    19     if (father[x]==x) return father[x];
    20     father[x]=find(father[x]);
    21     return father[x];
    22 }
    23 
    24 void merge(int x,int y)
    25 {
    26     int f1=find(x);
    27     int f2=find(y);
    28     father[f2]=f1;
    29 }
    30 
    31 int main()
    32 {
    33     cin>>n>>m;
    34     for (i=1;i<=n;++i)
    35         father[i]=i;
    36     for (i=1;i<=m;++i)
    37         cin>>sugar[i].x>>sugar[i].y>>sugar[i].cost;
    38     sort(sugar+1,sugar+m+1,cmp);
    39     
    40     for (i=1;i<=m;++i)
    41         if (find(sugar[i].x)!=find(sugar[i].y)&&n>k)
    42         {
    43             merge(sugar[i].x,sugar[i].y);
    44             ans=sugar[i].cost;
    45         }
    46     cout<<n-1<<' '<<ans;
    47 }
  • 相关阅读:
    跨域 jQuery库ajax请求
    跨域 响应请求
    跨域 XMLHttpRequest对象
    跨域 概述
    【网易官方】极客战记(codecombat)攻略-地牢-Kithgard 橱柜 A
    【网易官方】极客战记(codecombat)攻略-地牢-橱柜里的骷髅
    【网易官方】极客战记(codecombat)攻略-地牢-逃脱
    【网易官方】极客战记(codecombat)攻略-地牢-攻破突袭
    【网易官方】极客战记(codecombat)攻略-地牢-恐惧之门
    【网易官方】极客战记(codecombat)攻略-地牢-辐射光环
  • 原文地址:https://www.cnblogs.com/refun/p/8678422.html
Copyright © 2011-2022 走看看