zoukankan      html  css  js  c++  java
  • bzoj 1083: [SCOI2005]繁忙的都市

    裸最小生成树。。。一开始看是SCOI想应该没这么简单。

    结果真尼玛这么简单。。好意思!!

     1 /*
     2 ID:WULALA
     3 PROB:bzoj1083 
     4 LANG:C++
     5 */
     6 #include <cstdio>
     7 #include <cstring>
     8 #include <algorithm>
     9 #include <cmath>
    10 #include <iostream>
    11 #include <fstream>
    12 #include <ctime>
    13 #define N 308 
    14 #define M 10008 
    15 #define mod
    16 #define mid(l,r) ((l+r) >> 1)
    17 #define INF 0x7ffffff
    18 using namespace std;
    19 
    20 int n,m,fa[N],cnt,ans,tot;
    21 
    22 struct WULALA
    23 {
    24     int x,y,value;
    25 }e[2*M];
    26 
    27 void add(int x,int y,int w)
    28 {
    29     e[++cnt].value = w;
    30     e[cnt].y = y;
    31     e[cnt].x = x;
    32 }
    33 
    34 void init()
    35 {
    36     scanf("%d%d",&n,&m);
    37     for (int i = 1;i <= m;i++)
    38     {
    39         int a,b,c;
    40         scanf("%d%d%d",&a,&b,&c);
    41         add(a,b,c);
    42     }
    43     for(int i = 1;i <= n;i++) fa[i] = i;
    44 }
    45 
    46 bool cmp(WULALA a,WULALA b)
    47 {
    48     return (a.value < b.value);
    49 }
    50 
    51 int find(int a)
    52 {
    53     if (a == fa[a]) return a;
    54     return (fa[a] = find(fa[a]));
    55 }
    56 
    57 void work()
    58 {
    59     sort(&e[1],&e[cnt+1],cmp);
    60     for (int i = 1;i <= cnt;i++)
    61         if(find(e[i].x) != find(e[i].y))
    62         {
    63             ans = e[i].value;
    64             tot++;
    65             fa[find(e[i].x)] = e[i].y;
    66         } 
    67     printf("%d %d
    ",tot,ans);
    68 }
    69 
    70 int main()
    71 {
    72     init();
    73     work();
    74     return 0;
    75 } 
    View Code
  • 相关阅读:
    设定cookie 获取cookie数据的转换
    cookie cookie的获取
    常见的请求方式 json字符串
    请求报文和响应报文
    http协议
    php分页查询 子查询
    MAC 地址为什么不需要全球唯一
    ceph分布式存储简介
    一文看懂为什么边缘计算是大势所趋
    真香!Windows 可直接运行 Linux 了
  • 原文地址:https://www.cnblogs.com/wulala979/p/3507767.html
Copyright © 2011-2022 走看看