标签:return max problem others ott input nbsp turn space
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 40485 Accepted Submission(s):
13742
#include<iostream> #include<queue> #include<cstring> #include<cstdio> #define maxn 1090 using namespace std; int t,s,dd,ans,x,y,z,sumedge,maxnode; int head[maxn],dis[maxn],vis[maxn],wango[maxn]; queue<int>q; struct Edge{ int x,y,z,nxt; Edge(int x=0,int y=0,int z=0,int nxt=0): x(x),y(y),z(z),nxt(nxt){} }edge[maxn<<1]; void add(int x,int y,int z){ edge[++sumedge]=Edge(x,y,z,head[x]); head[x]=sumedge; } void spfa(){ memset(vis,0,sizeof(vis));vis[0]=1;q.push(0); memset(dis,0x3f,sizeof(dis));dis[0]=0; while(!q.empty()){ int now=q.front();q.pop();vis[now]=0; for(register int i=head[now];i;i=edge[i].nxt){ register int v=edge[i].y; if(dis[v]>dis[now]+edge[i].z){ dis[v]=dis[now]+edge[i].z; if(vis[v]==0)vis[v]=1,q.push(v); } } } } int main(){ while(~scanf("%d%d%d",&t,&s,&dd)){ sumedge=0; memset(head,0,sizeof(head)); for(register int i=1;i<=t;i++){ scanf("%d%d%d",&x,&y,&z); add(x,y,z);add(y,x,z); } for(register int i=1;i<=s;i++){ scanf("%d",&x); add(0,x,0);add(x,0,0); } for(register int i=1;i<=dd;i++)scanf("%d",&wango[i]); spfa();ans=0x7fffffff; for(register int i=1;i<=dd;i++)ans=min(ans,dis[wango[i]]); printf("%d\n",ans); } return 0; }
标签:return max problem others ott input nbsp turn space
原文地址:http://www.cnblogs.com/zzyh/p/7457423.html