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的太无奈了,如果哪位好人有时间看一下的话,先谢过了,RE了无数次,实在太郁闷了#include<iostream> #define NUM 200 using namespace std; typedef struct ArcNode { int adjvex; struct ArcNode *nextarc; int val; }ArcNode; typedef struct VNode { int val; ArcNode *firstarc; }VNode; VNode Node[NUM]; int n,s,e; int d[NUM]; void init() { int i,j; for(i=1;i<=n;++i) { d[i]=10000000; Node[i].firstarc=NULL; } d[s]=0; } void Bellman_Ford() { int times,i,j,k; ArcNode *p; for(times=1;times<n;++times) { for(i=1;i<=n;++i) { for(p=Node[i].firstarc;p!=NULL;p=p->nextarc) { if(d[p->adjvex]>(d[i]+p->val))d[p->adjvex]=d[i]+p->val; } } } } main() { int i,j,k,t; ArcNode *p; cin>>n>>s>>e; init(); for(i=1;i<=n;++i) { cin>>k; p=(ArcNode *)malloc(sizeof(ArcNode)); p->val=0; cin>>p->adjvex; p->nextarc=Node[i].firstarc; Node[i].firstarc=p; for(j=2;j<=k;++j) { p=(ArcNode *)malloc(sizeof(ArcNode)); p->val=1; cin>>p->adjvex; p->nextarc=Node[i].firstarc; Node[i].firstarc=p; } } Bellman_Ford(); if(d[e]==10000000)cout<<"-1"<<endl; else cout<<d[e]<<endl; system("pause"); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator