Xzz is a child with severe procrastinations. The new semester begins, He still has a lot of homework to do. Now, he needs your help. As the best friend, you are good at math. So, you will help him do some math homework. Now Xzz wants to go to your home. You can regard the traffic network as a undirected graph with n nodes (numbered from 1 to n) and m edges.
Xzz’s home at node s, and your at node t. At each node i, there is a traffic light, and the traffic light change the status after ai, which means that you can only leave node i, at time[0, ai), [2 * ai, 3 * ai), [4 * ai, 5 * ai), … , [2k * ai, (2 * k + 1) * ai). If ai = 0 means there is no traffic light, you can leave at any time. And there are m edges, each edge means it will take Xzz vi time from node xi to node yi. Now Xzz wants to know how much time he will take to arrive your home.
Input
First line of the input file contains an integer T(0
The description of each case is given below:
The first line of each case contains two numbers n, m, means there are n nodes and m edges.
(n ≤ 1000, m ≤ n(n-1) / 2)
Then follow n lines. In ith line there will be a number, ai.(ai ≤ 1000)
Then follow m lines. In ith line there will be three numbers, xi, yi and vi, means there is a edge between xi and yi, and Xzz take vi time to go trough this edge. vi ≤ 1000.
The last line contains two numbers s, t. It’s guarantee that there is at least one path between node s and t.
Output
One integer means the minimum time Xzz go to node t.
Sample Input
1
9 14
3
5
7
3
5
7
9
3
5
1 2 4
1 8 8
2 3 8
2 8 11
3 4 7
3 6 4
3 9 2
4 5 9
4 6 14
5 6 10
6 7 2
7 9 6
7 8 1
8 9 7
1 5
Sample Output
28
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define maxn 1000005
#define inf 0x3f3f3f3f
int a[maxn];
struct edge
{
int from,to,w,next;
}e[maxn];
int head[maxn],vis[maxn],dist[maxn];
int n,m ,t;
void add(int i,int j,int w)
{
e[t].from=i;
e[t].to=j;
e[t].w=w;
e[t].next=head[i];
head[i]=t++;
}
void spfa(int s)
{
queue q;
for(int i=1;inoww+e[i].w){
dist[v]=noww+e[i].w;
if(!vis[v]){
vis[v]=true;
q.push(v);
}
}
}
}
}
int main()
{
int T;cin>>T;
while(T--){
scanf("%d%d",&n,&m);
t=0;
memset(head,-1,sizeof(head));
memset(a,0,sizeof(a));
memset(e,0,sizeof(e));
for(int i=1;i>a[i];
while(m--){
int s,t,w;
scanf("%d%d%d",&s,&t,&w);
add(s,t,w);
add(t,s,w);
}
int start,ed;
scanf("%d%d",&start,&ed);
spfa(start);
cout
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net