讨论 / 最后一组数据傲娇??
CharlieYoung21 2013-10-14 04:16:00
点我顶贴 收藏 删除
为何最后一组我的是7554,正解8087??

其它9个点都对。

代码在此:

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <queue>

using namespace std;

const int maxn=30000+1000,maxm=150000+1000;

int head[maxn],dist[maxn],n,m,s=1,index=0;

bool check[maxn];

queue <int> q;

struct lu{

int to,next,weight;

}road[maxm];

void add(int u,int v,int w)

{

road[index].to=v;

road[index].next=head[u];

road[index].weight=w;

head[u]=index;

index++;

}

void spfa()

{

memset(check,0,sizeof(check));

dist[s]=0;

q.push(s);

check[s]=true;

while(!q.empty())

{

int top=q.front();

q.pop();

check[top]=false;

for(int i=head[top];i!=-1;i=road[i].next)

{

if(dist[top]+road[i].weight<dist[road[i].to])

{

dist[road[i].to]=dist[top]+road[i].weight;

if(!check[road[i].to])

{

q.push(road[i].to);

check[road[i].to]=true;

}

}

}

}

}

int main()

{

scanf("%d%d",&n,&m);

for(int i=1;i<=n;i++)

{

dist[i]=99999999;

head[i]=-1;

}

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);

}

spfa();

printf("%d\n",dist[n]);

return 0;

}

#1 allforbbs@2013-10-14 04:16:00
回复 删除
楼主智商拙计

数据傲娇为何会有AC?

为何总有选(S)手(B)质疑数据

#2 傻笨@2013-11-19 04:53:34
回复 删除
因为数组要开到30万,是双向的
查看更多回复
提交回复