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

英语不好的孩子你绝对伤不起!!!说白了就是求有无负环图!!!附代码!!!如有雷同天打雷劈

Posted by chenxuan123456789 at 2012-09-12 15:03:01 on Problem 3259
#include <stdio.h>
#include <string.h>
#define len 10050
typedef struct node
{
	int s;
	int e;
	int d;
}Node;
Node point[len];
int n,countedge;
void addedge(int s,int e,int d)
{
	point[countedge].s=s;
	point[countedge].e=e;
	point[countedge++].d=d;
}
int bellman()
{
	int dist[len],i,j,sum;
	for(i=1;i<=n;i++)
		dist[i]=10000000;
	dist[1]=0;
	for(i=1;i<n;i++)
		for(j=0;j<countedge;j++)
			if(dist[point[j].e]>dist[point[j].s]+point[j].d)
				dist[point[j].e]=dist[point[j].s]+point[j].d;
	for(i=0;i<countedge;i++)
     if(dist[point[i].e]>dist[point[i].s]+point[i].d)
		 return 1;
	 return 0;
}
int main()
{
	int cases,m,w;
	int s,e,d;
	scanf("%d",&cases);
	while(cases--)
	{
		scanf("%d %d %d",&n,&m,&w);
		countedge=0;
		while(m--)
		{
			scanf("%d %d %d",&s,&e,&d);
			addedge(s,e,d);
			addedge(e,s,d);
		}
		while(w--)
		{
			scanf("%d %d %d",&s,&e,&d);
			addedge(s,e,-d);
		}
		if(bellman())
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 1;
}




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