wa到死才发现inf太小了,10的10次方都不是够的!
#include<iostream>
#include<cmath>
#include<algorithm>
#define maxn 110
#define ll long long
using namespace std;
ll l1,l2,l3,l4,c1,c2,c3,c4;
int n,m;
ll sta[maxn];
ll dp[maxn][maxn];
int casee=1;
ll inf=1000000000000;
ll judge(int x,int y)
{
ll price=abs(sta[x]-sta[y]);
if(price>0&&price<=l1)
{
return c1;
}
if(price>l1&&price<=l2)
{
return c2;
}
if(price>l2&&price<=l3)
{
return c3;
}
if(price>l3&&price<=l4)
{
return c4;
}
return inf;
}
void init()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++) dp[i][j]=inf;
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
ll price=judge(i,j);
dp[i][j]=price;
dp[j][i]=price;
}
}
}
void input()
{
cin>>l1>>l2>>l3>>l4>>c1>>c2>>c3>>c4;
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>sta[i];
}
}
void solve()
{
cout<<"Case "<<casee++<<":"<<endl;
for(int i=0;i<m;i++)
{
int x,y;
cin>>x>>y;
if(dp[x-1][y-1]!=inf)
cout<<"The minimum cost between station "<<x<<" and station "<<y<<" is "<<dp[x-1][y-1]<<"."<<endl;
else cout<<"Station "<<x<<" and station "<<y<<" are not attainable."<<endl;
}
}
void flo()
{
for(int k=0;k<n;k++)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
//if(dp[i][k]!=inf&&dp[k][j]!=inf)
dp[i][j]=min(dp[i][k]+dp[k][j],dp[i][j]);
//cout<<dp[i][j]<<endl;
}
}
}
for(int i=0;i<n;i++) dp[i][i]=0;
}
int main()
{
//cin.sync_with_stdio(false);
int t;
cin>>t;
//cout<<inf<<"~"<<endl;
while(t--)
{
input();
init();
flo();
solve();
}
return 0;
}