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 |
Re:这题有点阴险,可能出现两条相同边!In Reply To:Re:这题有点阴险,可能出现两条相同边! Posted by:lyzardiar at 2011-03-14 12:10:29 郁闷了..... 邻接表写的 代码, 重边处理也太....... 空间换时间了, 结果还是 错...... 郁闷. 换成矩阵居然就A 了 代码: /* ID: baiyun2 PROG: Drainage Ditches LANG: C++ Mail to : miyubai@gamil.com My Blog : www.baiyun.me Author By : MiYu Test : 1 Complier : g++ mingw32-3.4.2 Program : POJ_1273 Doc Name : Drainage Ditches */ //#pragma warning( disable:4789 ) #include <iostream> #include <fstream> #include <sstream> #include <algorithm> #include <string> #include <set> #include <map> #include <utility> #include <queue> #include <stack> #include <list> #include <vector> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> using namespace std; void Debug () { #ifdef LOCAL freopen ( "1.in", "r", stdin ); freopen ( "1.out", "w", stdout ); #endif } struct P { int pos, val; P ( int a = 0, int b = 0 ) : pos(a),val(b) {} }; const int inf = 0x7fffffff; int N, M, x, y, val; int v[222], pre[222], flow[222][222], mp[222][222]; vector < P > vec[222]; int BFS () { queue < int > q; q.push ( 1 ); memset ( v, 0, sizeof ( v ) ); v[1] = inf; while ( !q.empty () ) { int t = q.front (); q.pop (); /* for ( int i = 0; i < vec[t].size (); ++ i ) { P &e = vec[t][i]; if ( !v[e.pos] && e.val > flow[t][e.pos] ) { v[e.pos] = min ( v[t], e.val - flow[t][e.pos] ); pre[e.pos] = t; q.push ( e.pos ); } } */ for ( int i = 1; i <= N; ++ i ) { if ( !v[i] && mp[t][i] > flow[t][i] ) { v[i] = min ( v[t], mp[t][i] - flow[t][i] ); pre[i] = t; q.push ( i ); } } } return v[N]; } int EK ( int res = 0 ) { memset ( flow, 0, sizeof ( flow ) ); while ( true ) { if ( val = BFS () ) { for ( int i = N; i != 1; i = pre[i] ) { flow[i][pre[i]] -= val; flow[pre[i]][i] += val; } res += val; } else break; } return res; } int main () { Debug (); while ( scanf ( "%d%d", &M, &N ) != EOF ) { memset ( mp, 0, sizeof ( mp ) ); //for ( int i = 1; i <= N; ++ i ) vec[i].clear (); for ( int i = 1; i <= M; ++ i ) { scanf ( "%d%d%d", &x, &y, &val ); mp[x][y] += val; //vec[x].push_back ( P ( y, mp[x][y] ) ); } printf ( "%d\n", EK () ); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator