Analysis: the minimum consumption of any two points can be obtained.

[Cpp]

# Include <iostream>

# Include <string>

# Include <cstring>

# Include <algorithm>

# Include <cstdio>

# Include <cmath>

# Include <iomanip>

Using namespace std;

Const int maxn = 1000 + 10;

Const _ int64 inf = 100000000002;

_ Int64 L1, L2, L3, L4, C1, C2, C3, C4;

_ Int64 map [maxn] [maxn];

_ Int64 d [maxn];

Int main (){

Int T; cin> T;

Int cas = 1;

While (T --){

Cin> L1> L2> L3> L4> C1> C2> C3> C4;

Int n, m; cin> n> m;

/// Initialization

For (int I = 1; I <= n; ++ I ){

Cin> d [I];

Map [I] [I] = 0;

For (int j = 1; j <I; ++ j ){

_ Int64 s = max (d [I], d [j])-min (d [I], d [j]), v;

If (s> L4) v = inf;

Else if (s> L3) v = C4;

Else if (s> L2) v = C3;

Else if (s> L1) v = C2;

Else if (s> 0) v = C1;

Else v = 0;

Map [I] [j] = map [j] [I] = v;

}

}

/// Floyd algorithm

For (int k = 1; k <= n; ++ k)

For (int I = 1; I <= n; ++ I)

For (int j = 1; j <= n; ++ j)

Map [I] [j] = min (map [I] [j], map [I] [k] + map [k] [j]);

Printf ("Case % d: \ n", cas ++ );

While (m --){

Int x, y; cin> x> y;

If (map [x] [y] = inf) printf ("Station % d and station % d are not attainable. \ n", x, y );

Else printf ("The minimum cost between station % d and station % d is % I64d. \ n", x, y, map [x] [y]);

}

}

Return 0;

}

# Include <iostream>

# Include <string>

# Include <cstring>

# Include <algorithm>

# Include <cstdio>

# Include <cmath>

# Include <iomanip>

Using namespace std;

Const int maxn = 1000 + 10;

Const _ int64 inf = 100000000002;

_ Int64 L1, L2, L3, L4, C1, C2, C3, C4;

_ Int64 map [maxn] [maxn];

_ Int64 d [maxn];

Int main (){

Int T; cin> T;

Int cas = 1;

While (T --){

Cin> L1> L2> L3> L4> C1> C2> C3> C4;

Int n, m; cin> n> m;

/// Initialization

For (int I = 1; I <= n; ++ I ){

Cin> d [I];

Map [I] [I] = 0;

For (int j = 1; j <I; ++ j ){

_ Int64 s = max (d [I], d [j])-min (d [I], d [j]), v;

If (s> L4) v = inf;

Else if (s> L3) v = C4;

Else if (s> L2) v = C3;

Else if (s> L1) v = C2;

Else if (s> 0) v = C1;

Else v = 0;

Map [I] [j] = map [j] [I] = v;

}

}

/// Floyd algorithm

For (int k = 1; k <= n; ++ k)

For (int I = 1; I <= n; ++ I)

For (int j = 1; j <= n; ++ j)

Map [I] [j] = min (map [I] [j], map [I] [k] + map [k] [j]);

Printf ("Case % d: \ n", cas ++ );

While (m --){

Int x, y; cin> x> y;

If (map [x] [y] = inf) printf ("Station % d and station % d are not attainable. \ n", x, y );

Else printf ("The minimum cost between station % d and station % d is % I64d. \ n", x, y, map [x] [y]);

}

}

Return 0;

}