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 样例和discuss里面数据都输出正确

Posted by lyz963254 at 2014-12-17 21:25:41 on Problem 1364
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

#define inf 99999999
#define M 502

struct e
{
    int u;
    int v;
    int w;
}edges[M];

int n,m;
int dist[M];
int ei ; //边的序号

bool bellman()
{
    int i,k,t;
   memset(dist,0,sizeof(dist));
        for(i=0;i<=n;i++){
                for(k=0;k<m;k++){
            t = dist[edges[k].u] + edges[k].w;
            if( dist[edges[k].v]>t) {
                dist[edges[i].v] = t;

            }
          }
        }
        for(k=0;k<m;k++){

            if(dist[edges[k].u]+edges[k].w<dist[edges[k].v]){
                return false;

            }
        }

    return true ;
}

int main ()
{   int i;
    while (scanf("%d",&n)!=EOF){
            if(n==0) break;
            scanf("%d",&m);
            char str[4];
            int u,v,w;

        for(i=0;i<m;i++){
        scanf("%d%d%s%d",&u,&v,str,&w);
        if(str[0]=='l'){
            edges[i].u = u-1;
            edges[i].v = u+v;
            edges[i].w = w - 1;
            ei++;
        }
        else {
            edges[i].u = u+v;
            edges[i].v = u - 1;
            edges[i].w = -w - 1;
            ei++;

        }

        }


       if(!bellman()) {
printf("successful conspiracy\n");
            

       }
       else  printf("lamentable kingdom\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