zoukankan      html  css  js  c++  java
  • 【bzoj1083】[SCOI2005]繁忙的都市

    1083: [SCOI2005]繁忙的都市

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 2424  Solved: 1591
    [Submit][Status][Discuss]

    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<cstdio>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<cmath>
     6 #include<ctime>
     7 #include<algorithm>
     8 using namespace std;
     9 struct node{int x,y,v;}e[20010];
    10 int n,m,ans,f[310];
    11 inline int read()
    12 {
    13     int x=0,f=1;  char ch=getchar();
    14     while(!isdigit(ch))  {if(ch=='-')  f=-1;  ch=getchar();}
    15     while(isdigit(ch))  {x=x*10+ch-'0';  ch=getchar();}
    16     return x*f;
    17 }
    18 int find(int x)  {return f[x]==x?x:f[x]=find(f[x]);}
    19 bool cmp(node a,node b)  {return a.v<b.v;}
    20 int main()
    21 {
    22     //freopen("cin.in","r",stdin);
    23     //freopen("cout.out","w",stdout);
    24     n=read();  m=read();
    25     for(int i=1;i<=m;i++)  {e[i].x=read();  e[i].y=read();  e[i].v=read();}
    26     sort(e+1,e+m+1,cmp);
    27     for(int i=1;i<=n;i++)  f[i]=i;
    28     for(int i=1;i<=m;i++)
    29     {
    30         int x=find(e[i].x),y=find(e[i].y);
    31         if(x!=y)  {f[x]=y;  ans=e[i].v;}
    32     }
    33     printf("%d %d
    ",n-1,ans);
    34     return 0;
    35 }
  • 相关阅读:
    团队展示
    原型设计(结对第一次)
    第二次作业——个人项目实战
    第一次作业--准备篇
    课程作业四
    课程作业三
    课程作业二
    课程作业一
    图像处理------ 一阶微分应用 (转载)
    dennis gabor 从傅里叶(Fourier)变换到伽柏(Gabor)变换再到小波(Wavelet)变换(转载)
  • 原文地址:https://www.cnblogs.com/chty/p/5945135.html
Copyright © 2011-2022 走看看