1003. Emergency (25)

Source: Internet
Author: User

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

Input

Each input file contains the one test case. For each test case, the first line contains 4 positive integers:n (<=)-The number of cities (and the cities is Numbered from 0 to N-1), m-the number of roads, C1 and c2-the cities, is currently in and so you must save, respectively. The next line contains N integers, where the i-th are 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 is the pair of cities connected by a R Oad and the length of that road, respectively. It is guaranteed this there exists at least one path from C1 to C2.

Output

For each test case, print on one line numbers:the number of different shortest paths between C1 and C2, and the maxim Um amount of rescue teams you can possibly gather.
All the numbers in a line must being separated by exactly one space, and there are 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

#include <cstdio> #include <algorithm> #include <string.h> #include <queue> #include <map >using namespace Std;int city[505][505];int teamnum[505];int dijkstra[505];bool isvisited[505];int Shortest, sumroad,sumteam;const int INF = 10000000;void init () {for (int i = 0; I < 505;i + +) isvisited[i] = false;}    void Dijkstra (int n,int begin,int end) {for (int i = 0; I < N;i + +) dijkstra[i] = City[begin][i];    Isvisited[begin] = true;        for (int i = 0; I < N-1;i + +) {int min = INF;        int flag = INF; for (int j = 0;j < N;j + +) if (isvisited[j] = = False && Dijkstra[j] < min) {min = di                JKSTRA[J];            flag = j;        } Isvisited[flag] = true;        if (flag = = end) break; for (int k = 0; k < n; k + +) if (isvisited[k] = = False && Dijkstra[flag] + city[flag][k] < Dijkstra [K]) dijkstra[k] = Dijkstra[flag] + city[flag][k];    }}void DFS (int begin,int end,int n,int curdis,int curteam) {Isvisited[begin] = true;            if (begin = = end) {if (Curdis = = shortest) {sumroad + +;        if (Curteam > Sumteam) sumteam = Curteam;    } return;  } for (int i = 0;i < n; i + +) {if (isvisited[i] = = False && City[begin][i]! = INF) if (Curdis            + City[begin][i] > shortest) continue;                else{DFS (I,end,n,curdis + City[begin][i],curteam + teamnum[i]);  Isvisited[i] = false; Key}} return;    int main (void) {int n,m,c1,c2;    scanf ("%d%d%d%d", &AMP;N,&AMP;M,&AMP;C1,&AMP;C2);    for (int i = 0;i < N;i + +) scanf ("%d", &teamnum[i]);            for (int p = 0;p < N;p + +) for (int q = 0;q < n;q++) if (p = = q) city[p][q] = 0;    else city[p][q] = INF;    for (int i = 0;i < N;i + +) dijkstra[i] = INF; for (iNT i = 0;i < N;i + +) isvisited[i] = false;        while (M) {int a,b,len;        scanf ("%d%d%d", &a,&b,&len);        CITY[A][B] = len;        City[b][a] = len;    m--;    } Dijkstra (N,C1,C2);    shortest = dijkstra[c2];    Init ();    DFS (C1,c2,n,0,teamnum[c1]);    printf ("%d%d", sumroad,sumteam);  return 0;}

1003. Emergency (25)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.