-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTRVCOST - Travelling cost.cpp
More file actions
48 lines (48 loc) · 1.01 KB
/
Copy pathTRVCOST - Travelling cost.cpp
File metadata and controls
48 lines (48 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#define MAXN 505
#define INT_MAX 9999999
using namespace std;
int graph[MAXN+1][MAXN+1];
int e,s,q;
void null()
{
for(int i=0; i<MAXN; i++)
for(int j=0; j<MAXN; j++)
{
if(i!=j)
graph[i][j]=INT_MAX;
else
graph[i][j]=0;
}
}
int main()
{
int ans;
int node=1;
int e,i,j,k,u,v,w;
cin>>e;
null();
for(i=0; i<e; i++)
{
cin>>u>>v>>w;
node=max(node,max(u,v));
graph[u][v]=min(graph[u][v],w);
graph[v][u]=min(graph[v][u],w);
}
for(k=0; k<=node; k++)
for(i=0; i<=node; i++)
for(j=0; j<=node; j++)
graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
int s,q,t;
cin>>s;
cin>>q;
for(i=0; i<q; i++)
{
cin>>t;
ans=min(graph[s][t],graph[t][s]);
if(ans==INT_MAX)
cout<<"NO PATH"<<endl;
else
cout<<ans<<endl;
}
}