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 |
FF超时,思路一样的代码0ms,求解啊~~~~~~无限TLE中。#include<cstdio> #include<cstring> #include<queue> #include<climits> #define MAX 250 using namespace std; int graph[MAX][MAX],link[MAX],n,m; int bfs() { queue<int> q; int x,min[MAX],i; min[1]=INT_MAX; memset(link,-1,sizeof(link)); q.push(1); while(!q.empty()) { x=q.front(); q.pop(); if(x==m) return min[m]; for(i=2;i<=m;i++) if(graph[x][i]!=0&&link[i]==-1) { link[i]=x; min[i]=min[x]<graph[x][i]?min[x]:graph[x][i]; q.push(i); } } return 0; } int cal() { int x,pre,now,i,ans; ans=0; while(x=bfs()&&x!=0) { now=m; while(now!=1) { pre=link[now]; graph[now][pre]+=x; graph[pre][now]-=x; now=pre; } ans+=x; } return ans; } int main() { int i,u,v,cost; while(scanf("%d%d",&n,&m)!=EOF) { memset(graph,0,sizeof(graph)); for(i=0;i<n;i++) { scanf("%d%d%d",&u,&v,&cost); graph[u][v]+=cost; } printf("%d\n",cal()); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator