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

题意:求从C1 到 C2的最短路方案数最大权值
题解:dijkstra。当距离相同时记得叠加方案数。
 #include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <string.h>
#define MAXX 100010
#define MMF(x) memset(x, 0, sizeof(x))
#define MMI(x) memset(x, INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = ; struct sion
{
int dic;
int amt;
int pcnt;
}C[N];
int mp[N][N];
bool vis[N];
int team[N]; void init(int &n)
{
MMF(vis);
for(int i = ; i < n; i++)
{
C[i].dic = INF;
C[i].pcnt = ;
C[i].amt = ;
for(int j = ; j < n; j++)
mp[i][j] = INF;
} }
void dijkstra(int &s, int &n)
{
queue<int>q;
vis[s] = ;
C[s].dic = ;
C[s].amt = team[s];
q.push(s);
//
while(!q.empty())
{
//cout << "~";
int now = q.front();
q.pop();
for(int i = ; i < n; i++)
{
if(!vis[i])
{ if(C[i].dic > C[now].dic + mp[now][i])
{
C[i].dic = C[now].dic + mp[now][i];
C[i].amt = C[now].amt + team[i];
C[i].pcnt = C[now].pcnt;
}
else if(C[i].dic == C[now].dic + mp[now][i])
{
C[i].pcnt += C[now].pcnt;
if(C[i].amt < C[now].amt + team[i])
C[i].amt = C[now].amt + team[i];
}
}
}
int mi = INF;
int x;
for(int i = ; i < n; i++)
{
if(!vis[i] && C[i].dic < mi)
{
mi = C[i].dic;
x = i;
}
//cout << C[i].dic << endl;
}
if(mi == INF)
break;
q.push(x);
vis[x] = ;
}
return ;
} int main()
{
int n, m, s, t;
int x, y, z;
scanf("%d%d%d%d", &n, &m, &s, &t);
for(int i = ; i < n; i++)
scanf("%d", &team[i]);
init(n);
for(int i = ; i < m; i++)
{
scanf("%d%d%d", &x, &y, &z);
if(mp[x][y] >= z)
mp[x][y] = mp[y][x] = z;
}
dijkstra(s, n); printf("%d %d\n", C[t].pcnt, C[t].amt); }

 

PAT (Advanced level) 1003. Emergency (25) Dijkstra的更多相关文章

  1. PAT (Advanced Level) 1003. Emergency (25)

    最短路+dfs 先找出可能在最短路上的边,这些边会构成一个DAG,然后在这个DAG上dfs一次就可以得到两个答案了. 也可以对DAG进行拓扑排序,然后DP求解. #include<iostrea ...

  2. PAT 解题报告 1003. Emergency (25)

    1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...

  3. PAT Advanced 1003 Emergency (25) [Dijkstra算法]

    题目 As an emergency rescue team leader of a city, you are given a special map of your country. The ma ...

  4. PTA (Advanced Level) 1003 Emergency

    Emergency As an emergency rescue team leader of a city, you are given a special map of your country. ...

  5. PAT (Advanced Level) 1078. Hashing (25)

    二次探测法.表示第一次听说这东西... #include<cstdio> #include<cstring> #include<cmath> #include< ...

  6. PAT (Advanced Level) 1070. Mooncake (25)

    简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...

  7. PAT (Advanced Level) 1029. Median (25)

    scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...

  8. PAT (Advanced Level) 1010. Radix (25)

    撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ...

  9. PAT (Advanced Level) 1032. Sharing (25)

    简单题,不过数据中好像存在有环的链表...... #include<iostream> #include<cstring> #include<cmath> #inc ...

随机推荐

  1. Coins and Queries(map迭代器+贪心)

    题意 n个硬币,q次询问.第二行给你n个硬币的面值(保证都是2的次幂!).每次询问组成b块钱,最少需要多少个硬币? Example Input 5 42 4 8 2 4851410 Output 1- ...

  2. Java 集合框架之Collection

    此图是 java 中 Collection 相关的接口与类的关系的类图.其中,类只是集合框架的一部分,比较常用的一部分. 第一次画类图,着实很费劲,不过收获也不小. 下面是相关接口和类的解释说明.文字 ...

  3. C++第一次课堂作业 circle

    Github上的代码提交

  4. Deeplearning——Logistics回归

    资料来源:1.博客:http://binweber.top/2017/09/12/deep_learning_1/#more——转载,修改更新 2.文章:https://www.qcloud.com/ ...

  5. lintcode-189-丢失的第一个正整数

    189-丢失的第一个正整数 给出一个无序的正数数组,找出其中没有出现的最小正整数. 样例 如果给出 [1,2,0], return 3 如果给出 [3,4,-1,1], return 2 挑战 只允许 ...

  6. Android 布局方式学习

    一.LinearLayout线性布局: 线性布局是程序中最常见的一种布局方式,线性布局可以分为水平线性布局和垂直线性布局两种, 通过android:orientation属性可以设置线性布局的方向 1 ...

  7. thinkPHP框架单一入口文件解析

    一.index.php  (可参考ThinkPHP学习手册http://document.thinkphp.cn/manual_3_2.html#entrance_file) index.php单入口 ...

  8. WPF中DataGrid的应用-绑定,增改删,分页,样式

    参考以下网址: http://www.cnblogs.com/fwbnet/archive/2012/05/08/2490974.html

  9. VBA练习-复杂一点

    '日期添加 Sub addDate(d) Dim rg As Range, dd As Date d = Split(d, ) d = Replace(d, ".", " ...

  10. 【Python】爬虫与反爬虫大战

    爬虫与发爬虫的厮杀,一方为了拿到数据,一方为了防止爬虫拿到数据,谁是最后的赢家? 重新理解爬虫中的一些概念 爬虫:自动获取网站数据的程序反爬虫:使用技术手段防止爬虫程序爬取数据误伤:反爬虫技术将普通用 ...