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

我的AC代码 真心欢迎各位大牛指正错误!

Posted by 911016 at 2011-04-22 20:12:16 on Problem 1860
#include<iostream>
using namespace std;
const double MIN=-1<<30;
 
 struct Edge{
    int a,b;
    double c,r;              
};
 
bool bellman_ford(Edge* e,double* d,int s,double q,int n,int m){
    int i,j;
    for(i=1;i<=n;i++)
        d[i]=MIN;    
    d[s]=q;
    bool flag;
    for(i=1;i<=n;i++){
        flag=true;
        for(j = 1; j <= m; j++)
            if(d[e[j].a]>0&&d[e[j].b] <(d[e[j].a] - e[j].c) * e[j].r ){             
               d[e[j].b]  = (d[e[j].a] - e[j].c) * e[j].r;               
                flag =false;
             }                
        if(flag)   return false; 
    }
    return true;    
}

int main(){
    int n,m,s;
    double q;
    Edge e[300];
    double d[105];
    scanf("%d%d%d%lf",&n,&m,&s,&q);
    int i;
    int a,b;
    double r,c;
    for(i=1;i<=m;i++){
        scanf("%d%d%lf%lf",&a,&b,&r,&c);
        e[i].a=a;e[i].b=b;e[i].r=r;e[i].c=c;            
        scanf("%lf%lf",&r,&c);
        e[m+i].a=b;e[m+i].b=a;e[m+i].r=r;e[m+i].c=c;
    }
    if(bellman_ford(e,d,s,q,n,2*m))
        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