zoukankan      html  css  js  c++  java
  • 2012年亚洲长春区域赛:E Conquer a New Region

    E - Conquer a New Region

    E - Conquer a New Region
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

    Description

     

    The wheel of the history rolling forward, our king conquered a new region in a distant continent.

    There are N towns (numbered from 1 to N) in this region connected by several roads. It's confirmed that there is exact one route between any two towns. Traffic is important while controlled colonies are far away from the local country. We define the capacityC(ij) of a road indicating it is allowed to transport at most C(ij) goods between town i and town j if there is a road between them. And for a route between i and j, we define a value S(ij) indicating the maximum traffic capacity between i and j which is equal to the minimum capacity of the roads on the route.

    Our king wants to select a center town to restore his war-resources in which the total traffic capacities from the center to the other N- 1 towns is maximized. Now, you, the best programmer in the kingdom, should help our king to select this center.

    Input 

    There are multiple test cases.

    The first line of each case contains an integer N. ( 1$ \le$N$ \le$200, 000)

    The next N - 1 lines each contains three integers abc indicating there is a road between town a and town b whose capacity is c. ( 1$ \le$ab$ \le$N1$ \le$c$ \le$100, 000)

    Output 

    For each test case, output an integer indicating the total traffic capacity of the chosen center town.

    Sample Input 

    4
    1 2 2
    2 4 1
    2 3 1
    4
    1 2 1
    2 4 1
    2 3 1

    Sample Output 

    4
    3
    

     解题思路:因为一条路上的运输力是限制于路上最小的流量, 那麽边按流量大到小排序后,再进行处理。

    解题代码:

    View Code
     1 // File Name: E - Conquer a New Region
     2 // Author: sheng
     3 // Created Time: 2013年04月18日 星期四 10时31分37秒
     4 
     5 #include <iostream>
     6 #include <stdio.h>
     7 #include <string.h>
     8 #include <algorithm>
     9 using namespace std;
    10 const int Maxn = 2e5+5;
    11 typedef long long LL;
    12 
    13 struct node
    14 {
    15     int x, y;
    16     int w;
    17     bool operator < (const node t1) const
    18     {
    19         return w > t1.w;
    20     }
    21 }town[Maxn];
    22 
    23 LL sum[Maxn];
    24 int cnt[Maxn];
    25 int fa[Maxn];
    26 
    27 int find(int x)
    28 {
    29     if (x != fa[x])
    30         return fa[x] = find(fa[x]);
    31     return x;
    32 }
    33 
    34 int main()
    35 {
    36     int i, n, a, b, c;
    37     while (scanf ("%d", &n) == 1)
    38     {
    39         for (i = 1; i < n; i ++)
    40             scanf ("%d%d%d", &town[i].x, &town[i].y, &town[i].w );
    41         for (i = 1; i <= n; i ++)
    42         {
    43             sum[i] = 0;
    44             cnt[i] = 1;
    45             fa[i] = i;
    46         }
    47         sort (town + 1, town + n);
    48         LL ans = 0;
    49         for (i = 1; i < n; i ++)
    50         {
    51             a = find (town[i].x);
    52             b = find (town[i].y);
    53             LL atob = (LL) cnt[a] * town[i].w + sum[b];
    54             LL btoa = (LL) cnt[b] * town[i].w + sum[a];
    55             if (atob > btoa )
    56             {
    57                 fa[a] = b;
    58                 cnt[b] += cnt[a];
    59                 sum[b] = atob;
    60             }
    61             else
    62             {
    63                 fa[b] = a;
    64                 cnt[a] += cnt[b];
    65                 sum[a] = btoa;
    66             }
    67             ans = max (ans, max(atob, btoa));
    68         }
    69         printf ("%lld\n", ans);
    70     }
    71 }
     
  • 相关阅读:
    【Wyn Enterprise BI知识库】 什么是商业智能 ZT
    Wyn BI的机会在哪里:越靠近消费者的行业,比如零售、文娱和金融,信息化投入越大 ZT
    客户化软件时代的前夜 ZT
    在“非软件企业”开发软件的困局 ZT
    行业观察报告:从SAAS困局看行业趋势 ZT
    超级干货 :一文读懂数据可视化 ZT
    传统BI还是自助式BI---BI与数据分析 ZT
    【BI学习笔记】在Linux上安装Wyn Enterprise商业智能报表服务器
    MAMP 配置: Mac with OSX 10.8 + (Mac + Apache + MySQL + Php)
    Emule Xtreme Kid eD2K 设置
  • 原文地址:https://www.cnblogs.com/shengshouzhaixing/p/3028240.html
Copyright © 2011-2022 走看看