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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cstdlib> #include<climits> #include<stack> #include<vector> #include<queue> #include<set> #include<map> #include<string>
#include<cstdio> using namespace std; #define ll long long #define maxn 1010 #define inf 0x3f3f3f3f bool vis[maxn]; vector<int>p; ll dis[maxn],cnt; struct node { int v,cap,next; node(){} node(int v,int cap):v(v),cap(cap){} bool operator < (const node &a)const { return cap>a.cap; } }edge[maxn*maxn]; int head[maxn];
void add(int u,int v,int cap) { edge[cnt].v=v; edge[cnt].cap=cap; edge[cnt].next=head[u]; head[u]=cnt; cnt++; } void dijkstra(int s,int city) { for(int i=1;i<=city;i++)dis[i]=inf; priority_queue<node>q; dis[s]=0; q.push(node(s,0)); while(!q.empty()) { node s=q.top();q.pop(); int u=s.v; for(int i=head[s.v];i!=-1;i=edge[i].next) { int v=edge[i].v; int cap=edge[i].cap; if(dis[v]>dis[u]+cap) { dis[v]=dis[u]+cap; q.push(node(v,dis[v])); } } } return ; } int main() { int t; scanf("%d",&t); while(t--) { memset(head,-1,sizeof(head)); cnt = 0; int n,m,s,k,c; scanf("%d %d %d %d %d",&n,&m,&s,&k,&c); int sups = 0; for(int i=0;i<k;i++) { int x; scanf("%d",&x); add(sups,x,0); add(x,sups,0); } for(int i=1;i<=m;i++) { int u,v,w; scanf("%d %d %d",&u,&v,&w); add(u,v,w); add(v,u,w); } dijkstra(sups,n); ll maxa = -1; for(int i=1;i<=n;i++) { maxa = max(maxa,dis[i]); } dijkstra(s,n); ll maxb = -1; for(int i=1;i<=n;i++) { maxb= max(maxb,dis[i]); } if(maxa*c<maxb) printf("%lld\n",maxa); else printf("%lld\n",maxb); } }
|