国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

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

2019-11-06 09:24:21
字體:
供稿:網(wǎng)友

1003. Emergency (25) 時(shí)間限制: 400 ms內(nèi)存限制: 65536 kB代碼長度限制: 16000 B判題程序:Standard
  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. Examples

Input
5 6 0 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1
Output
2 4

  Notes   【acm】 作者   CHEN, Yue

  在Dijkstra算法的基礎(chǔ)上,增加隊(duì)伍數(shù)量和路徑數(shù)的確定,當(dāng)?shù)竭_(dá)某點(diǎn)的多條路長度相同時(shí),考慮隊(duì)伍數(shù)量最大化。   

#include <iostream>#include <algorithm>#include <map>#include <vector>#include <functional>#include <string>#include <cstring>#include <queue>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <sstream>#include <iomanip>using namespace std;#define IOS ios_base::sync_with_stdio(false)#define TIE std::cin.tie(0)#define MIN2(a,b) (a<b?a:b)#define MIN3(a,b) (a<b?(a<c?a:c):(b<c?b:c))#define MAX2(a,b) (a>b?a:b)#define MAX3(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))typedef long long LL;typedef unsigned long long ULL;const int INF = 0x3f3f3f3f;const double PI = 4.0*atan(1.0);const double eps = 0.000001;const int maxn = 505;int n, m, c1, c2, L;int st, en;int teams[maxn];struct Edge{ int form, to, dist; //Edge(int u, int v, int d) :form(u), to(v), dist(d){}};struct HeapNode{ int d, u; bool Operator < (const HeapNode &a)const { return d > a.d; }};struct Dijkstra{ vector<Edge> edge; vector<int> G[maxn]; int d[maxn], p[maxn], t[maxn]; bool done[maxn]; void init() { for (int i = 0; i < n; i++) G[i].clear(); edge.clear(); } void addEdge(const Edge &e) { edge.push_back(e); G[e.form].push_back(edge.size() - 1); } void dijkstra(int s) { for (int i = 0; i < n; i++) d[i] = INF; for (int i = 0; i < n; i++) t[i] = 0; for (int i = 0; i < n; i++) p[i] = 0; memset(done, 0, sizeof(done)); d[s] = 0; p[s] = 1; t[s] = teams[s]; priority_queue<HeapNode> que; que.push(HeapNode{0,s}); while (que.size()){ HeapNode x = que.top(); que.pop(); if (done[x.u]) continue; done[x.u] = true; for (int i = 0; i < G[x.u].size(); i++){ Edge &e = edge[G[x.u][i]]; if (d[e.to] > d[x.u] + e.dist){ d[e.to] = d[x.u] + e.dist; p[e.to] = p[x.u]; t[e.to] = t[x.u] + teams[e.to]; } else if (d[e.to] == d[x.u] + e.dist){ if (t[e.to] < t[x.u] + teams[e.to]) t[e.to] = t[x.u] + teams[e.to]; p[e.to] += p[x.u]; } que.push(HeapNode{ d[e.to], e.to }); } } }};int main(){ scanf("%d%d%d%d", &n, &m, &st, &en); Dijkstra dj; dj.init(); for (int i = 0; i < n; i++){ scanf("%d", &teams[i]); } for (int i = 0; i < m; i++){ scanf("%d%d%d", &c1, &c2, &L); dj.addEdge(Edge{ c1, c2, L }); dj.addEdge(Edge{ c2, c1, L }); } dj.dijkstra(st); printf("%d %d/n", dj.p[en], dj.t[en]); //system("pause");}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 江门市| 贞丰县| 泰顺县| 白朗县| 晋江市| 乡宁县| 株洲市| 金溪县| 海盐县| 昌都县| 邵阳县| 太和县| 会理县| 武乡县| 宿迁市| 新野县| 平远县| 清远市| 新田县| 林芝县| 礼泉县| 千阳县| 汉中市| 龙州县| 桐城市| 黄石市| 招远市| 宜丰县| 南平市| 萨迦县| 烟台市| 延安市| 黑龙江省| 罗平县| 桃源县| 眉山市| 龙山县| 始兴县| 江源县| 阿巴嘎旗| 大宁县|