zoukankan      html  css  js  c++  java
  • Matrix

    Description
    Machines have once again attacked the kingdom of Xions. The kingdom of Xions has N cities and N-1 bidirectional roads. The road network is such that there is a
    unique path between any pair of cities.

    Morpheus has the news that K Machines are planning to destroy the whole kingdom. These Machines are initially living in K different cities of the kingdom and
    anytime from now they can plan and launch an attack. So he has asked Neo to destroy some of the roads to disrupt the connection among Machines. i.e after destroying those roads there should not be any path between any two Machines.

    Since the attack can be at any time from now, Neo has to do this task as fast as possible. Each road in the kingdom takes certain time to get destroyed and they
    can be destroyed only one at a time.

    You need to write a program that tells Neo the minimum amount of time he will require to disrupt the connection among machines.
    Input
    The first line is an integer T represents there are T test cases. (0<T <=10)
    For each test case the first line input contains two, space-separated integers, N and K. Cities are numbered 0 to N-1. Then follow N-1 lines, each containing three, space-separated integers, x y z, which means there is a bidirectional road connecting city x and city y, and to destroy this road it takes z units of time.Then follow K lines each containing an integer. The ith integer is the id of city in which ith Machine is currently located.
    2 <= N <= 100,000
    2 <= K <= N
    1 <= time to destroy a road <= 1000,000
    Output
    For each test case print the minimum time required to disrupt the connection among Machines.
    SampleInput
    1
    5 3
    2 1 8
    1 0 5
    2 4 5
    1 3 4
    2
    4
    0
    SampleOutput
    10
    
  • 相关阅读:
    Visual Studio 2019 Xamarin 设计器显示不正常
    Chrome 关闭稍后阅读/阅读清单功能
    Chrome 浏览器历史记录的日期格式转换 sqlite3
    将博客搬至CSDN
    python selenium 库利用 pytesseract 识别验证码方案
    layui OSS Web直传
    苹果App Store审核被拒记录(持续更新中...)
    iOS RSA加密解密
    PHP、Android、iOS接口RSA加密解密
    安卓RSA加密解密(简单复制直接使用)
  • 原文地址:https://www.cnblogs.com/to-creat/p/5005124.html
Copyright © 2011-2022 走看看