21746_Trave

2022-5-16 18:20| 发布者: Hocassian| 查看: 23| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505812348200-Problem List-采集的数据-后羿采集器.html

Pro.ID

21746

Title

Travel

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21746

AC

3

Submit

6

Ratio

50.00%

时间&空间限制

  • Time Limit: 6000/3000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    PP loves travel. Her dream is to travel around country A which consists of N cities and M roads connecting them. PP has measured the money each road costs. But she still has one more problem: she doesn't have enough money. So she must work during her travel. She has chosen some cities that she must visit and stay to work. In City_i she can do some work to earn Ci money, but before that she has to pay Di money to get the work license. She can't work in that city if she doesn't get the license but she can go through the city without license. In each chosen city, PP can only earn money and get license once. In other cities, she will not earn or pay money so that you can consider Ci=Di=0. Please help her make a plan to visit all chosen cities and get license in all of them under all rules above.
    PP lives in city 1, and she will start her journey from city 1. and end her journey at city 1 too.

    输入

    The first line of input consists of one integer T which means T cases will follow.
      Then follows T cases, each of which begins with three integers: the number of cities N (N 100) , number of roads M (M ≤ 5000) and her initiative money Money (Money 10^5) .
      Then follows M lines. Each contains three integers u, v, w, which means there is a road between city u and city v and the cost is w. u and v are between 1 and N (inclusive), w 10^5.
      Then follows a integer H (H 15) , which is the number of chosen cities.
      Then follows H lines. Each contains three integers Num, Ci, Di, which means the i_th chosen city number and Ci, Di described above.(Ci, Di 10^5)

    输出

    Description

    PP loves travel. Her dream is to travel around country A which consists of N cities and M roads connecting them. PP has measured the money each road costs. But she still has one more problem: she doesn't have enough money. So she must work during her travel. She has chosen some cities that she must visit and stay to work. In City_i she can do some work to earn Ci money, but before that she has to pay Di money to get the work license. She can't work in that city if she doesn't get the license but she can go through the city without license. In each chosen city, PP can only earn money and get license once. In other cities, she will not earn or pay money so that you can consider Ci=Di=0. Please help her make a plan to visit all chosen cities and get license in all of them under all rules above.
    PP lives in city 1, and she will start her journey from city 1. and end her journey at city 1 too.

    Input

    The first line of input consists of one integer T which means T cases will follow.
      Then follows T cases, each of which begins with three integers: the number of cities N (N 100) , number of roads M (M ≤ 5000) and her initiative money Money (Money 10^5) .
      Then follows M lines. Each contains three integers u, v, w, which means there is a road between city u and city v and the cost is w. u and v are between 1 and N (inclusive), w 10^5.
      Then follows a integer H (H 15) , which is the number of chosen cities.
      Then follows H lines. Each contains three integers Num, Ci, Di, which means the i_th chosen city number and Ci, Di described above.(Ci, Di 10^5)

    Output

    If PP can visit all chosen cities and get all licenses, output "YES", otherwise output "NO".

    Sample Input
    2
    4 5 10
    1 2 1
    2 3 2
    1 3 2
    1 4 1
    3 4 2
    3
    1 8 5
    2 5 2
    3 10 1
    2 1 100
    1 2 10000
    1
    2 100000 1
    Sample Output

    YES
    NO

    Source
    Author

    样例输入

    2
    4 5 10
    1 2 1
    2 3 2
    1 3 2
    1 4 1
    3 4 2
    3
    1 8 5
    2 5 2
    3 10 1
    2 1 100
    1 2 10000
    1
    2 100000 1

    样例输出

    YES
    NO

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部