[] SSL1624 little trouble Sa [floyed shortest variant]

Description

Sa will be given a small map, it can be seen as an FIG (N <= 100) of nodes N. This map has N bus stop, you can only Sa small bus on the N bus station. There is a two-way path between some stations, either bus or small Sa, you can only take these pathways. If the distance between two stations is time d, as required walking 2 * d seconds, the time required for the bus d seconds. They only small Sa T seconds, he wants you back in time to find whether he and his MM out on a date, if not, then output "You are day dreaming!", Otherwise the output time they need to spend a minimum of .
Note : a bus ticket can be used twice (you can only ride with a bus), which can be considered equal time to date Sa small place and back in time.

Meaning of the questions:

There is a map of n * n, from point 1 to point s, have a chance to halve the time to ask the shortest time.

Input

The first line contains three integers N, T, S
followed by a N * N adjacency matrix. The distance between every two stations does not exceed 10 ^ 9. A [I, j] is 0 means no communication stations I and J.

Output

If they are not small Sa back to school for a limited time, then the output "You are day dreaming!" (Without the quotation marks)
. Otherwise, output an integer, the minimum time it takes for what they need.

Sample Input

4 5 4
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0

Sample Output

2

Hint

[Data] range
of 20% of data: N <= 10
100% of the data is: N <= 70 T <= 10 ^ 9

analysis

This problem also with two adjacency matrix (a walk a car). Shortest start and again, then each edge binary, and finally enumerate the most appropriate place, the starting point to the most appropriate place to take a minimum, while the minimum is the answer.

The Code

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
LL n,t,s,g[101][101],ans,a[101][101];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>t>>s;
	for(register LL i=1;i<=n;i++)
	{
		for(register LL j=1;j<=n;j++)
		{
			cin>>g[i][j];
			if(!g[i][j]) g[i][j]=0x7fffffff;
			if(i==j) g[i][j]=0;
			a[i][j]=g[i][j]*2; //走路两倍时间
		}
	}
	for(register LL k=1;k<=n;k++)
	  for(register LL i=1;i<=n;i++)
	    for(register LL j=1;j<=n;j++)
	      a[i][j]=min(a[i][j],a[i][k]+a[k][j]);//坐车
	ans=0x7fffffff;
	for(register LL i=1;i<=n;i++)
	  for(register LL j=1;j<=n;j++)
     	ans=min(ans,g[i][j]+a[1][i]+a[j][s]);  //走路
	if(2*ans>t/*往返如果超时*/) 
	{
		std::cout<<"You are day dreaming!" ;
	}
	else std::cout<<ans*2;
	return 0; 
}

Published 31 original articles · won praise 23 · views 783

Guess you like

Origin blog.csdn.net/dglyr/article/details/104011501