Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位大牛指点一下,为什么wa呢#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator