比赛 近期练习题回顾 评测结果 AAAAAAAAAA
题目名称 过路费 最终得分 100
用户昵称 @@@ 运行时间 0.793 s
代码语言 C++ 内存使用 14.16 MiB
提交时间 2018-10-25 10:09:25
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
int n,m,q;
int e[255][255],f[255][255];
int r[255];

int point[255];
bool mmp(int x,int y)
{
	return point[x] < point[y];
}
int main()
{
	freopen("toll.in","r",stdin);
	freopen("toll.out","w",stdout);
	scanf("%d%d%d",&n,&m,&q);
	
	for(int i = 1;i <= n;i++)
	{
		r[i] = i;
		for(int j = 1;j <= n;j++)
		{
			f[i][j] = e[i][j] = 1e9;
		}
		e[i][i] = 0;
	}
	for(int i = 1;i <= n;i++)
	{
		scanf("%d",&point[i]);
	}
	int u,v,w;
	sort(r+1,r+1+n,mmp);
	for(int i = 1;i <= m;i++)
	{
		scanf("%d%d%d",&u,&v,&w);
		//e[r[u]][r[v]] = w;
		e[u][v] = min(e[u][v],w);
		//e[r[v]][r[u]] = w;
		e[v][u] = e[u][v];
	}
	
	for(int l = 1;l <= n;l++)
	{
		int k = r[l];
		for(int ii = 1;ii <= n;ii++)
		{
			int i = ii;
			for(int jj = 1;jj <= n;jj++)
			{
				int j = jj;
				e[i][j] = min(e[i][j],e[i][k]+e[k][j]);
				f[i][j] = min(f[i][j],e[i][j]+max(point[k],max(point[i],point[j])));
			}
		}
	}
	for(int i = 1;i <= q;i++)
	{
		scanf("%d%d",&u,&v);
		printf("%d\n",f[u][v]);
	}
	return 0;
	
}