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 <iostream> using namespace std; struct Edge { unsigned int start; unsigned int end; int weight; }; int F, N, M, W, S, E, T, Edge_size; int* d; Edge* e; inline void relax(Edge *e) { if (d[e->start] + e->weight < d[e->end]) d[e->end] = d[e->start] + e->weight; } bool bellman_ford() { for (int i = 0; i < N; ++i) d[i] = 0; for (int i = 0; i < N - 1; ++i) { for (int j = 0; j < Edge_size; ++j) relax(&e[j]); } for (int i = 0; i < Edge_size; ++i) { if (d[e->start] + e->weight < d[e->end]) return true; } return false; } int main() { cin >> F; while (F--) { cin >> N >> M >> W; Edge_size = 2 * M + W; d = new int[N]; e = new Edge[Edge_size]; for (int i = 0; i < 2 * M; i = i + 2) { cin >> S >> E >> T; e[i].start = (--S); e[i].end = (--E); e[i].weight = T; e[i + 1].start = E; e[i + 1].end = S; e[i + 1].weight = T; } for (int i = 2 * M; i < Edge_size; ++i) { cin >> S >> E >> T; e[i].start = (--S); e[i].end = (--E); e[i].weight = -T; } if (bellman_ford()) cout << "YES" << endl; else cout << "NO" << endl; delete[] d; delete[] e; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator