• 1003. Emergency (25)


     

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

    Input

    Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.

    Output

    For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather.
    All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

    Sample Input
    5 6 0 2
    1 2 1 5 3
    0 1 1
    0 2 2
    0 3 1
    1 2 1
    2 4 1
    3 4 1
    
    Sample Output
    2 4
     1 #include <stdio.h>
     2 #include<string.h>
     3 
     4 #define MAX 510
     5 int INF = 100000;
     6 int w[MAX];
     7 int wight[MAX];
     8 int d[MAX];
     9 int num[MAX];
    10 int Grap[MAX][MAX];
    11 bool visit[MAX];
    12 
    13 void Dijkstra(int begin,int NodeNum)
    14 {
    15     d[begin] = 0;
    16     w[begin] = wight[begin];
    17     num[begin] = 1;
    18     for(int i = 0; i < NodeNum ;i++)
    19     {
    20         int index = -1;
    21         int Min = INF ;
    22         for(int j = 0 ;j < NodeNum;j++)  //找出距离起点最近节点
    23         {
    24             if(visit[j] == false && d[j] < Min)
    25             {
    26                 index = j;
    27                 Min = d[j];
    28             }
    29         }
    30 
    31         if(index == -1) //如果找不出小于INF的节点,说明剩下的节点都与起点不连通
    32             return ;
    33         visit[index] = true ;
    34 
    35         for(int v = 0;v < NodeNum;v++)
    36         {
    37             if(visit[v] == false && Grap[index][v]!=INF)
    38             {
    39                 if(d[index] + Grap[index][v] < d[v])
    40                 {
    41                     d[v] = d[index] + Grap[index][v];
    42                     w[v] = w[index] + wight[v];
    43                     num[v] = num[index];
    44                 }
    45                 else if(d[index] + Grap[index][v] == d[v])
    46                 {
    47                     if(w[index] + wight[v] > w[v])
    48                         w[v] = w[index] + wight[v];
    49                     num[v] = num[index] + num[v]; 
    50                 }
    51             }
    52         }
    53     }
    54 }
    55 int main()
    56 {
    57     int i,NodeNum,EdgNum,Begin,End;
    58     scanf("%d%d%d%d",&NodeNum,&EdgNum,&Begin,&End);
    59 
    60     for(i = 0 ;i < NodeNum ;i++)
    61     {
    62         for(int j = 0 ; j < NodeNum ; j++)
    63             Grap[i][j] = INF ;
    64 
    65         w[i] = 0;
    66         num[i] = 0;
    67         d[i] = INF ;
    68         visit[i] = false;
    69     }
    70 
    71 
    72     for(i = 0 ; i < NodeNum ; i ++)
    73     {
    74         scanf("%d",&wight[i]);
    75     }
    76     int x,y;
    77     for( i = 0;i< EdgNum ;i++)
    78     {
    79         scanf("%d%d",&x,&y);
    80         scanf("%d",&Grap[x][y]);
    81         Grap[y][x] = Grap[x][y];
    82     }
    83 
    84     Dijkstra(Begin,NodeNum);
    85     printf("%d %d
    ",num[End],w[End]);
    86     return 0;
    87 }


  • 相关阅读:
    2017/12/30Java基础学习——增强型for嵌套遍历在二维数组中的应用
    2017/12/30Java基础学习——复制数组のSystem.arraycopy()方法讲解
    2017/12/30Java基础学习——排序算法の选择法与冒泡法的比较
    2017/12/31Java基础学习——二维数组排序の数组工具类Arrays的方法综合运用
    2017/12/31Java基础学习——使用同一个值,填充整个数组のArrays.fill(a, number)方法
    2017/12/31Java基础学习——判断两个数组是否相同のArrays.equals(a, b)方法
    2017/12/31Java基础学习——查找数组元素位置のArrays.binarySearch()方法介绍
    HDU2030 汉字统计【输入输出流】
    HDU4509 湫湫系列故事——减肥记II【格式输入+存储设置+暴力+水题】
    HDU2567 寻梦【输入输出流】
  • 原文地址:https://www.cnblogs.com/xiaoyesoso/p/4290991.html
Copyright © 2020-2023  润新知