Moving On 第 44 届 ACM/ICPC 亚洲区域赛(银川)网络赛

Firdaws and Fatinah are living in a country with nnn cities, numbered from 111 to nnn. Each city has a risk of kidnapping or robbery.

Firdaws's home locates in the city uuu, and Fatinah's home locates in the city vvv. Now you are asked to find the shortest path from the city uuu to the city vvv that does not pass through any other city with the risk of kidnapping or robbery higher than www, a threshold given by Firdaws.
Input

The input contains several test cases, and the first line is a positive integer TTT indicating the number of test cases which is up to 505050.

For each test case, the first line contains two integers n(1≤n≤200)n (1 \le n \le 200)n(1≤n≤200) which is the number of cities, and q(1≤q≤2×104)q (1 \le q \le 2 \times 10^4)q(1≤q≤2×104) which is the number of queries that will be given. The second line contains nnn integers r1,r2,⋯ ,rnr_1, r_2, \cdots , r_nr1​,r2​,⋯,rn​ indicating the risk of kidnapping or robbery in the city 111 to nnn respectively. Each of the following nnn lines contains nnn integers, the jjj-th one in the iii-th line of which, denoted by di,jd_{i,j}di,j​, is the distance from the city iii to the city jjj.

Each of the following qqq lines gives an independent query with three integers u,vu,vu,v and www, which are described as above.

We guarantee that 1≤ri≤105,1≤di,j≤105(i≠j),di,i=01 \le r_i \le 10^5, 1 \le d_{i,j} \le 10^5 (i \neq j), d_{i,i} = 01≤ri​≤105,1≤di,j​≤105(i​=j),di,i​=0 and di,j=dj,id_{i,j} = d_{j,i}di,j​=dj,i​. Besides, each query satisfies 1≤u,v≤n1 \le u,v \le n1≤u,v≤n and 1≤w≤1051 \le w \le 10^51≤w≤105.
Output

For each test case, output a line containing Case #x: at first, where xxx is the test case number starting from 111. Each of the following qqq lines contains an integer indicating the length of the shortest path of the corresponding query.

输出时每行末尾的多余空格,不影响答案正确性
样例输入

1
3 6
1 2 3
0 1 3
1 0 1
3 1 0
1 1 1
1 2 1
1 3 1
1 1 2
1 2 2
1 3 2

样例输出

Case #1:
0
1
3
0
1
2
#include
using namespace std;
const int N=210;
struct node
{
	int xh;int r;
}v[N];
int mp[N][N][N]; 
int cmp(node x,node y)
{
	return x.r<y.r;
}
//思想大概是弗洛伊德不停的往递增k 即可以承受的风险
//k是从一到n 表示n个点的风险值的排序号
// 不断的往路中加入允许的风险的点 
int main()
{
	int tt;
	scanf("%d",&tt);int index=0;
	while(tt--)
	{
		printf("Case #%d:\n",++index);
		int n,m;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++) 
		{
		   scanf("%d",&v[i].r );
		   v[i].xh=i;
		}
		sort(v+1,v+1+n,cmp);
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				scanf("%d",&mp[0][i][j]);
			} 
		} 
		for(int k=1;k<=n;k++)
		{
			for(int i=1;i<=n;i++)
			{
				for(int j=1;j<=n;j++)
				{
					int tp=mp[k-1][i][v[k].xh ]+mp[k-1][v[k].xh ][j];
					if(tp>=mp[k-1][i][j])
					{
						mp[k][i][j]=mp[k-1][i][j];
					} else mp[k][i][j]=tp;
				} 
			}
		}
		while(m--)
		{
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);int st=0;
			if(a==b)
			{
				printf("0\n");
				continue;
			}
			for(int i=1;i<=n;i++)
			{
				if(v[i].r <=c)
				//在很多个risk的值重复的情况下,sort并没有进行去重操作,那么根据上面的
				//三重循环k 越大存在的最短路应该是越优秀的
				//要往后找到那个可以允许的风险值最大的情况 
				{
					st=i;
				} else break;
			} 
			
			printf("%d\n",mp[st][a][b]);
		}
	}
}

你可能感兴趣的:(第,44,届,ACM/ICPC,亚洲区域赛(银川)网络赛)