Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用的是bellman-ford感觉没错啊,谁能告诉我为什么wa

Posted by batmancn at 2010-09-09 21:34:35 on Problem 3259
#include "iostream"
#include "vector"
#define MAXNUM 9999999

using namespace std;

typedef struct edge {
	int s;
	int e;
	int cost;
}edge;

int main(void)
{
	int f,n,m,w,s,e,t;
	int i,j;
	int d[500];
	vector<edge> edges;
	vector<edge>::iterator iter;
	edge temp;
	freopen("in.txt","r",stdin);
	cin>>f;
L1:	while (f--!=0) {
		cin>>n>>m>>w;
		for (i=0;i<m;i++) {
			cin>>s>>e>>t;
			s--;
			e--;
			temp.s=s;
			temp.e=e;
			temp.cost=t;
			edges.push_back(temp);
			temp.s=e;
			temp.e=s;
			temp.cost=t;
			edges.push_back(temp);
		}
		for (i=0;i<w;i++) {
			cin>>s>>e>>t;
			s--;
			e--;
			temp.s=s;
			temp.e=e;
			temp.cost=-t;
			edges.push_back(temp);
		}
		for (i=0;i<500;i++) {
			d[i]=MAXNUM;
		}
		d[0]=0;
		for (i=1;i<n;i++) {
			for (iter=edges.begin();iter!=edges.end();iter++) {
				if (d[iter->s]>d[iter->e]+iter->cost) {
					d[iter->s]=d[iter->e]+iter->cost;
				}
			}
		}
		for (iter=edges.begin();iter!=edges.end();iter++) {
			if (d[iter->s]>d[iter->e]+iter->cost) {
				cout<<"YES\n";
				goto L1;
			}
		}
		cout<<"NO\n";
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator