| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:为什么会runtime error啊,实在看不出来什么错,不得已贴个代码,哪位大大帮忙看看In Reply To:为什么会runtime error啊,实在看不出来什么错,不得已贴个代码,哪位大大帮忙看看 Posted by:anotherh at 2006-05-20 12:05:56 实在不知道上面的代码有什么问题...不过强烈推荐SPFA.又好写,又快的东西!
#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>
using namespace std;
vector<pair<int,int> > g[505];
int path[505],queue[500001];
bool check[505];
int i,m,f,p,c,op,cl;
void read_graph()
{
int i,a,b,s;
scanf("%d %d %d %d",&f,&p,&c,&m);
for (i=1;i<=p;i++)
{
scanf("%d %d %d",&a,&b,&s);
g[a].push_back(make_pair(b,s));g[b].push_back(make_pair(a,s));
}
}
void init()
{
int i;
memset(check,false,sizeof(check));
memset(queue,false,sizeof(queue));
for (i=1;i<=f;i++) path[i]=2147483647;
}
void do_SPFA()
{
int temp,tempnode,i;
op=1;cl=0;queue[1]=1;path[1]=0;check[1]=true;
while (cl<op)
{
cl++;
temp=queue[cl];
for (i=0;i<g[temp].size();i++)
{
tempnode=g[temp][i].first;
if (path[tempnode]>(path[temp]+g[temp][i].second))
{
path[tempnode]=path[temp]+g[temp][i].second;
if (!check[tempnode]) {op++;queue[op]=tempnode;check[tempnode]=true;}
}
}
check[temp]=false;
}
}
void show_ans()
{
int cow[105],total=0,i;
for (i=1;i<=c;i++)
{
scanf("%d",&cow[i]);
if (path[cow[i]]<=m) total++;
}
printf("%d\n",total);
for (i=1;i<=c;i++) if (path[cow[i]]<=m) printf("%d\n",i);
}
int main()
{
read_graph();
init();
do_SPFA();
show_ans();
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator