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. android BadgeView的使用(图片上的文字提醒)

    BadgeView主要是继承了TextView,所以实际上就是一个TextView,底层放了一个label,可以自定义背景图,自定义背景颜色,是否显示,显示进入的动画效果以及显示的位置等等: 这是Gi ...

  2. lintcode-142-O(1)时间检测2的幂次

    142-O(1)时间检测2的幂次 用 O(1) 时间检测整数 n 是否是 2 的幂次. 样例 n=4,返回 true; n=5,返回 false. 挑战 O(1) time 标签 比特位操作 思路 使 ...

  3. jenkins部署springboot多项目

    war包的部署问题不大,这里记录jar包的部署过程: 1:jar包的体积过大问题 pom.xml参考以下配置(依赖包会分离到target/lib/,jar包体积由几十M缩小到几k) <build ...

  4. 在select中,载入时默认select为空白,选项内不显示空白项

    有两种办法,一种纯css实现,一种借助js实现. html: <body onload="load()"> <select id="abc" ...

  5. 在mvc返回JSON时出错:序列化类型为“System.Data.Entity.DynamicProxies.Photos....这个会的对象时检测到循环引用 的解决办法

    在MVC中返回JSON时出错,序列化类型为“System.Data.Entity.DynamicProxies.Photos....这个会的对象时检测到循环引用. public ActionResul ...

  6. 【bzoj1727】[Usaco2006 Open]The Milk Queue 挤奶队列 贪心

    题目描述 Every morning, Farmer John's N (1 <= N <= 25,000) cows all line up for milking. In an eff ...

  7. P3808 【模板】AC自动机(简单版)

    题目背景 这是一道简单的AC自动机模板题. 用于检测正确性以及算法常数. 为了防止卡OJ,在保证正确的基础上只有两组数据,请不要恶意提交. 管理员提示:本题数据内有重复的单词,且重复单词应该计算多次, ...

  8. SOA,ESB,WebService的关系

    1. 什么是SOA SOA(Service-Oriented Architecture)既服务导向架构,是指为了解决在inernet环境下业务集成的需要,通过连接能完成特定任务的独立功能实现的一种软件 ...

  9. Unable to open connection to "Microsoft SQL Server, provider V1.0.5000.0 in framework

    解决办法:1 以管理员身份登陆2 找到ORACLE_HOME文件夹(D:\oracle\ora92),点右键,选属性——安全,在组或用户栏中选"Authenticated Users&quo ...

  10. 算法训练 Bus Tour

    问题描述 想象你是一个在Warsaw的游客,而且预订了一次乘车旅行,去城镇外看一些令人惊异的景点.这辆公共汽车首先围绕城镇行驶一段时间(一段很长的时间,由于Warsaw是一个大城市),把在各自旅馆的人 ...