21602_Hostipa

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

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

Pro.ID

21602

Title

Hostipal

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Given a directed graph G = (V, E), each node represents a city. In order to provide medical service in cities, a few hospitals need to be built in some of the cities. For some reasons, one hospital can just be put in one city, and two hospitals can not be put in two adjacent cities. Two cities i and j are considered adjacent if and only if there is an edge from i to j or from j to i. So there might be some cities have no hospitals in them, people of those cities can require the hospital to send doctors to their cities. Of course people will choose the city which is the closest to call. But if the closest city to travel is still far away, people would not satisfy with the quality of the medical service since much time would be taken on the travel. The dissatisfaction of people of the city which has no hospital can be measured as following:

    S[i] = (number of edges from the closest hospital to city i / 3) * U

    i is the city without hospital, and U is a constant integer, which will be given as input. And "/" means integer division. Your task is finding a plan of putting hospitals in cities so that the sum of dissatisfaction of the cities without hospitals is minimum. Note that you should make sure the service cover all cities, which means that there should no city can not be serviced.

    Figure 1 is an example with four nodes. Supposed U is 10. If we put one hospital in node 4, so the node 1 will have a dissatisfaction of 10. A perfect plan is to put a hospital in node 2 and node 4.

    Figure 1   Example with four nodes

    输入

    Input may consist of several test data sets. For each data set, it can be formatted as below:

    First line comes with two integers, N and M, the number of nodes and edges. 1 ≤ N ≤ 100,  0 ≤ M ≤ 10000.

    Then comes M lines, each line has two integers x and y, 1 ≤ x, yN, representing an edge from node x to node y,  xy.

    Finally comes an integer U, the constant number described as above. 1 ≤ U ≤ 500.

    Input is ended with N = M = 0.

    输出

    Description

    Given a directed graph G = (V, E), each node represents a city. In order to provide medical service in cities, a few hospitals need to be built in some of the cities. For some reasons, one hospital can just be put in one city, and two hospitals can not be put in two adjacent cities. Two cities i and j are considered adjacent if and only if there is an edge from i to j or from j to i. So there might be some cities have no hospitals in them, people of those cities can require the hospital to send doctors to their cities. Of course people will choose the city which is the closest to call. But if the closest city to travel is still far away, people would not satisfy with the quality of the medical service since much time would be taken on the travel. The dissatisfaction of people of the city which has no hospital can be measured as following:

    S[i] = (number of edges from the closest hospital to city i / 3) * U

    i is the city without hospital, and U is a constant integer, which will be given as input. And "/" means integer division. Your task is finding a plan of putting hospitals in cities so that the sum of dissatisfaction of the cities without hospitals is minimum. Note that you should make sure the service cover all cities, which means that there should no city can not be serviced.

    Figure 1 is an example with four nodes. Supposed U is 10. If we put one hospital in node 4, so the node 1 will have a dissatisfaction of 10. A perfect plan is to put a hospital in node 2 and node 4.

    Figure 1   Example with four nodes

    Input

    Input may consist of several test data sets. For each data set, it can be formatted as below:

    First line comes with two integers, N and M, the number of nodes and edges. 1 ≤ N ≤ 100,  0 ≤ M ≤ 10000.

    Then comes M lines, each line has two integers x and y, 1 ≤ x, yN, representing an edge from node x to node y,  xy.

    Finally comes an integer U, the constant number described as above. 1 ≤ U ≤ 500.

    Input is ended with N = M = 0.

    Output

    For each data set, first output one integer in one line, representing the minimum dissatisfaction of the optimal plan. Then output one integer in second line, representing the number of hospitals of your plan. Finally output all city numbers which has hospitals in one line in ascending order, separated with one blank space.

    Sample Input

    4 3
    2 1
    4 3
    3 2
    10
    0 0

    Sample Output

    0
    2
    2 4

    Source

    样例输入

    4 3
    2 1
    4 3
    3 2
    10
    0 0

    样例输出

    0
    2
    2 4

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部