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 Airforce2007 at 2010-05-10 14:06:56 on Problem 1201
#include <stdio.h>
#include <string.h>
#define Max 50002

struct Edge{int u,v,w;}E[Max*10];
int dis[Max], n, m, len;

void Bellman_ford()
{
     memset(dis, 0, sizeof(dis));
     
     for(int i = 0; i < m; ++i)
     {
           bool flag = false;
           for(int j = 0; j < len; ++j)
           if(dis[E[j].v] < dis[E[j].u] + E[j].w)
           {
                dis[E[j].v] = dis[E[j].u] + E[j].w;
                flag = true;
           }
           if(!flag) break;    
     }
}      

inline void adde(int i, int j, int k)
{
       E[len].u = i;
       E[len].v = j;
       E[len].w = k;
       ++len;
}

int main()
{
    freopen("in.txt", "r", stdin);
    int i, j, k, val;
    while(scanf("%d", &n) != EOF)
    {
          m = len = 0;
          for(i = 0; i < n; ++i)
          {
                scanf("%d%d%d", &j, &k, &val); 
                adde(j, ++k, val);
                if(m < k) m = k;
          }
          for(i = 0; i < m; ++i)
          {
                adde(i, i+1, 0);
          }

          Bellman_ford();
          printf("%d\n", dis[m]);
    }
    
    while(1);
    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