可惜没如果=_=
时光的河入海流

1083: [SCOI2005]繁忙的都市

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 3621  Solved: 2264
[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

HINT

 

Source

难得一道完全自主知识产权的题=_= 然而是道水题……

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 typedef long long LL;
 4 const int MAX1=305;
 5 const int MAX2=MAX1*MAX1/2;
 6 int n,m,fa[MAX1],ans;
 7 struct Edge{
 8     int u,v,w;
 9     bool operator < (const Edge &tt) const {
10         return w<tt.w;
11     }
12 }edge[MAX2];
13 int getfather(int x){return fa[x]==x?x:fa[x]=getfather(fa[x]);}
14 bool feasible(int x){
15     int i,j,zt;
16     zt=0;
17     for (i=1;i<=n;i++) fa[i]=i;
18     for (i=1;i<=m;i++){
19         if (edge[i].w>x) continue;
20         int tx=getfather(edge[i].u);
21         int ty=getfather(edge[i].v);
22         if (tx!=ty){
23             fa[tx]=ty;
24             zt++;
25         }
26     }
27     return (zt>=(n-1));
28 }
29 int main(){
30     freopen ("city.in","r",stdin);freopen ("city.out","w",stdout);
31     int i,j,low=1e9,high=0,mid,u,v,w;
32     scanf("%d%d",&n,&m);
33     for (i=1;i<=m;i++){
34         scanf("%d%d%d",&u,&v,&w);
35         edge[i]=(Edge){u,v,w};
36         high=max(high,w),low=min(low,w);
37     }
38     sort(edge+1,edge+m+1);
39     while (low<=high){
40         mid=(low+high)>>1;
41         if (feasible(mid)) ans=mid,high=mid-1;
42         else low=mid+1;
43     }
44     printf("%d %d",n-1,ans);
45     return 0;
46 }

 

posted on 2017-10-24 15:24  珍珠鸟  阅读(159)  评论(0编辑  收藏  举报