麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

PAT甲級1003

2019-11-14 09:19:40
字體:
供稿:網(wǎng)友

1003. Emergency (25)

時間限制400 ms內(nèi)存限制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 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1Sample Output
2 4
#include<cstdio>#include<vector>#include<queue>#include<algorithm>using namespace std;const int maxn = 500;const int INF = 1000000000;struct Node{	int v, dis;}node;struct compare{	bool Operator()(Node n1, Node n2)	{		return n1.dis > n2.dis;	}};//自定義比較器vector<Node> Adj[maxn];//圖的鄰接表形式int N, M, C1, C2, c1, c2, L;int weight[maxn] = { 0 };//記錄各頂點的權(quán)bool vis[maxn] = { false };//標(biāo)記頂點是否被訪問int d[maxn], w[maxn],//統(tǒng)計最短路徑、最大點權(quán)num[maxn];//統(tǒng)計最短路徑數(shù)void Dijkstra(int s){	fill(d, d + maxn, INF);	fill(w, w + maxn, 0);	fill(num, num + maxn, 0);	d[s] = 0;	w[s] = weight[s];//對增加點權(quán)的問題初始化	num[s] = 1;//對增加路徑數(shù)的問題初始化	priority_queue<Node,vector<Node>,compare>Q;//找出最小的u,我這里沒用窮舉方式,用堆優(yōu)化一下	node.v = s; node.dis = d[s];	Q.push(node);	int u;	for (int i = 0; i < N; i++)	{		if (!Q.empty())		{			u = Q.top().v;			vis[u] = true;			Q.pop();		}		else			return;//已經(jīng)沒有要處理的點了,可以返回了		for (int j = 0; j < Adj[u].size(); j++)		{			int v = Adj[u][j].v;			int dis = Adj[u][j].dis;//注意這里是邊長			if (!vis[v])			{				if (d[u] + dis < d[v])				{					d[v] = d[u] + dis;					w[v] = weight[v] + w[u];					num[v] = num[u];//優(yōu)化情形下直接繼承					node.v = v; node.dis = d[v];//注意這里的dis是更新為起點到當(dāng)前點的距離					Q.push(node);				}				else if (d[u] + dis == d[v])				{					num[v] += num[u];//相等則累加					if(w[v]<weight[v] + w[u])						w[v] = weight[v] + w[u];//總是更新為最大點權(quán)                                                                                                    				}			}		}	}}int main(){	scanf("%d%d%d%d", &N, &M, &C1, &C2);	for (int i = 0; i < N; i++)	{		scanf("%d", &weight[i]);	}	for (int i = 0; i < M; i++)	{		scanf("%d%d%d", &c1, &c2, &L);		node.v = c2;		node.dis = L;		Adj[c1].push_back(node);		node.v = c1;		Adj[c2].push_back(node);	}	Dijkstra(C1);	printf("%d %d/n", num[C2], w[C2]);	return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产免费高清在线视频 | 激情小说另类 | 精品国产一区二区三区久久久狼牙 | 欧美精品免费一区二区三区 | 福利在线免费视频 | 在火车上摸两乳爽的大叫 | 亚洲一级片免费观看 | 91在线视频在线观看 | 久久国产在线观看 | 亚洲天堂岛国片 | 九九热在线视频观看这里只有精品 | 性毛片视频 | 国产精品久久久久久久久久iiiii | 中文字幕激情视频 | 欧美毛片 | 久久久久久久久久久久久久av | 高颜值美女啪啪 | 九九视频在线观看黄 | 欧美日本色| 男女羞羞在线观看 | 欧美韩国一区 | 视频一区二区三区在线播放 | 久色婷婷| 久久一区三区 | 国产午夜电影在线观看 | 久久精品伊人网 | 黄视频免费在线观看 | 国产一区免费视频 | 欧美毛片 | 在线香蕉视频 | 欧美中文字幕一区二区 | 欧美爱爱视频免费看 | 羞羞视频在线免费 | 精品一区二区三区日本 | 一级@片| 黄色片在线免费播放 | 黄色成人av在线 | 日韩毛片在线看 | 成人性视频免费网站下载软件 | 国产韩国精品一区二区三区久久 | hd极品free性xxx一护士 |