BZOJ1083: [SCOI2005]繁忙的都市

水题之王SP…这题就裸的最小生成树

 1 /**************************************************************
 2     Problem: 1083
 3     User: zhuohan123
 4     Language: C++
 5     Result: Accepted
 6     Time:32 ms
 7     Memory:1404 kb
 8 ****************************************************************/
 9  
10 #include <iostream>
11 #include <cstdio>
12 #include <algorithm>
13 using namespace std;
14 struct edge
15 {
16     int u,v,c;
17     friend bool operator<(edge a,edge b){return a.c<b.c;}
18 }g[11000];
19 int f[310];
20 int gf(int p){return f[p]==p?p:f[p]=gf(f[p]);}
21 int main(int argc, char *argv[])
22 {
23     int n,m;scanf("%d%d",&n,&m);
24     for(int i=1;i<=n;i++)f[i]=i;
25     for(int i=1;i<=m;i++)scanf("%d%d%d",&g[i].u,&g[i].v,&g[i].c);
26     sort(g+1,g+m+1);
27     int bmax=0;
28     for(int i=1;i<=m;i++)
29         if(gf(g[i].u)!=gf(g[i].v))
30         {
31             bmax=g[i].c;
32             f[gf(g[i].u)]=gf(g[i].v);
33         }
34     printf("%d %d\n",n-1,bmax);
35     return 0;
36 }

 

posted @ 2013-08-14 21:29  zhuohan123  阅读(275)  评论(0编辑  收藏  举报