zoukankan      html  css  js  c++  java
  • uva 12655 Trucks [LCA](树链剖分+MST)

    The Subtle Balloons Company (SBC) is the main balloon provider for programming contests; it has
    huge factories and warehouses, as well as an extensive truck
    eet to ensure the contestants' happiness.
    There are lots of competition sites in Nlogonia, and all of them hired SBC for supplying balloons for
    their contests. Nlogonia is an archipelago connected by several bridges. Every island of Nlogonia may
    have several regional sites and may also house several SBC warehouses.
    When planning the routes for balloon deliveries, SBC faced a problem: for safety issues, every
    bridge in Nlogonia has some maximum weight limit for vehicles which cross it. And because of the
    great net weight of the transported merchandise, SBC operations' chief asked you to write a program to
    determine the maximum weight allowed to be transported between warehouses and competition sites.
    Input
    The input contains several test cases. The rst line of a test case contains three integers N, M and S
    which indicate, respectively, the number of islands, the number of bridges that connect the islands and
    the number of sites. The islands are numbered from 1 to N.
    Each of the next M lines describes a bridge. The description of a bridge consists in a line with
    three integers A, B and W, indicating respectively the two islands connected by the bridge and the
    maximum weight allowed in that bridge, in tons.
    All bridges are two-way roads; every pair of islands is connected by at most one bridge; and it is
    possible to reach every other island in the archipelago using only bridges (naturally it may be needed
    to pass through other islands to do so).
    Each of the next S lines describe a competition site and contains two integers L and H indicat-
    ing, respectively, the number of the island where this site is and the number of the island where the
    wharehouse which will be used to deliver the balloons to the site is.
    Output
    For each site in a test case, in the order they were given, your program must produce a single line,
    containing a single integer, the biggest weight which can be transported by truck from the warehouse
    to the site.
    Restrictions

    • 2 ≤ N ≤ 2 × 104
    • 1 ≤ M ≤ 105
    • 1 ≤ S ≤ 5 × 104
    • 1 ≤ A, B, L, H ≤ N, A ̸= B, L ̸= H
    • 0 ≤ W ≤ 105


    Sample Input
    4 5 4
    1 2 9
    1 3 0
    2 3 8
    2 4 7
    3 4 4
    1 4
    2 1
    3 1
    4 3
    4 5 2
    1 2 30
    2 3 20
    3 4 10
    4 1 40
    2 4 50
    1 3
    1 2


    Sample Output
    7
    9
    8
    7
    20
    40

    1: 如果(u,v)为轻边,则size(v)<=size(u)/2;

    2: 从根到某一点的路径上轻边的个数不大于O(logN)

    时间复杂度O(N*logN*logN)

    树链剖分:

    view code
  • 相关阅读:
    Unity NGUI 2D场景添加按钮
    EaseType缓动函数
    在没有网络的情况下用安卓手机和数据线让台式电脑上网
    面向对象编程
    static与C#中的static
    C#基础
    iSensor APP 之 摄像头调试 OV5642
    iSensor APP 之 摄像头调试 OV9655
    USB3.0之高速视频传输测试 双目相机(mt9p031、mt9m001)带宽高达300M测试 配合isensor测试 500万像素15fps
    模拟摄像头解码模块最新测试 TVP5150模块 FPGA+SDRAM+TVP5150+VGA 实现PAL AV输入 VGA视频输出
  • 原文地址:https://www.cnblogs.com/zyx1314/p/3911574.html
Copyright © 2011-2022 走看看