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

求助!!一直WA~

Posted by remijohn at 2011-08-17 21:24:42 on Problem 1860
#include<stdio.h>

#define eps 1e-8
//The structure of edges.
struct edge
{
  int head,tail;
  double r,c;
}edge[220];

bool Bellmenford(int numOfNode,int numOfEdge,double v,int s)
{
  double capital[numOfNode+10]; //The array to represent the nodes.
  
  int i,j;
  bool change=true;

  capital[s]=v;
  while(capital[s]+eps <= v)
    {
      change=false;
      for(j=0;j<numOfEdge;j++)
	{
	  if( (capital[edge[j].tail]+eps)<(capital[edge[j].head]-edge[j].c)*edge[j].r)
	    {
	      capital[edge[j].tail]=( capital[edge[j].head]-edge[j].c )*edge[j].r;
	      change=true;
	    }
	}
      if(change==false)
	{
	  if(capital[s]+eps >v)
	    return true;
	  else 
	    return false;
	}
    }
  return true;
}
  

int main()
{
  int n,m,s;
  double v;

  scanf("%d%d%d%lf",&n,&m,&s,&v);
  int i;
  for(i=0;i<m;i++)
    {
      scanf("%d%d%lf%lf%lf%lf",&edge[2*i].head,&edge[2*i].tail,&edge[2*i].r,&edge[2*i].c,&edge[2*i+1].r,&edge[2*i+1].c);
      edge[2*i+1].head=edge[2*i].tail;
      edge[2*i+1].tail=edge[2*i].head;
    }
  if(Bellmenford(n,2*m,v,s))
    printf("YES\n");
  else
    printf("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