标签:存在 set 输入 str 工作 tac content ota AC
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 80836 Accepted Submission(s): 34999
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<stack> #include<stdlib.h> #include<map> #include<vector> #include<queue> #include<set> #include<ctype.h> #define zuida 100000 using namespace std; #define INF 1e9 #define max 100005 struct node { int to; int val; int next; }bian[max]; int head[max],vis[max]; int n,m; int tto=0; void add(int a,int b,int c) { bian[tto].to=b; bian[tto].val=c; bian[tto].next=head[a]; head[a]=tto++; } int dis[max]; int que[max]; queue<int> qq; void spfa(int start,int num) { memset(vis,0,sizeof(vis)); for(int i=0;i<=num;i++) dis[i]=INF; //int front=-1,tail=-1; //dis[start]=0;vis[start]=1;que[++tail]=start; qq.push(start);dis[start]=0;vis[start]=1; int top,to; int temp; /*while(front!=tail) { if(++front==n)front-=num; top=que[front];vis[top]=0; for(int p=head[top];p!=-1;p=bian[p].next) { to=bian[p].to; temp=dis[top]+bian[p].val; if(dis[to]>temp) { dis[to]=temp; if(!vis[to]) { if(++tail>num)tail-=num; que[tail]=to; vis[to]=1; } } } } */ while(!qq.empty()) { top=qq.front();qq.pop();vis[top]=0; for(int p=head[top];p!=-1;p=bian[p].next) { to=bian[p].to; temp=dis[top]+bian[p].val; if(dis[to]>temp) { dis[to]=temp; if(!vis[to]) { qq.push(to); vis[to]=1; } } } } } int main() { int b,w,m,k; while(cin>>n>>m&&n&&m) { int maxx=-100000; memset(head,-1,sizeof(head)); for(int i=1;i<=m;i++) { cin>>k>>b>>w; if(k>maxx)maxx=k; if(b>maxx)maxx=b; add(k,b,w); add(b,k,w); } spfa(1,maxx); cout<<dis[n]<<endl; } return 0; }
标签:存在 set 输入 str 工作 tac content ota AC
原文地址:https://www.cnblogs.com/SparkPhoneix/p/8877231.html