当前位置: 代码迷 >> 综合 >> hdu 2680
  详细解决方案

hdu 2680

热度:26   发布时间:2023-11-24 14:42:47.0

题目 :Problem - 2680 (hdu.edu.cn)

#include<bits/stdc++.h>
using namespace std;
#define MXN 1010
#define inf 0x3f3f3f3f
int Map[MXN][MXN],dist[MXN],visit[MXN]; 
int main(){int n,m,s,p,q,t;while(scanf("%d %d %d",&n,&m,&s)==3){memset(Map,inf,sizeof Map);memset(dist,inf,sizeof dist);memset(visit,0,sizeof visit);for(int i=0;i<m;i++){scanf("%d %d %d",&p,&q,&t);Map[p][q]=min(Map[p][q],t);}int w,a=0;scanf("%d",&w);while(w--){scanf("%d",&p);Map[a][p]=0;}int Min,next;visit[a]=1;dist[a]=0;while(a!=s){Min=inf;for(int i=0;i<=n;i++){if(visit[i]==1){continue;}if(Map[a][i]!=inf){dist[i]=min(dist[i],dist[a]+Map[a][i]);	}if(dist[i]<Min){next=i;Min=dist[i];}}if(Min==inf){break;}a=next;visit[a]=1;}if(dist[s]==inf/*a!=s*/){printf("-1\n");}else{printf("%d\n",dist[s]);}}return 0;
}