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

Why?? This code is not Accept I don't Understand.(Prob Id 1273)

Posted by LpG_Master at 2008-03-23 14:22:02 and last updated at 2008-03-23 14:23:13
#include <stdio.h>
#include <queue>

using namespace std;

long N=0;
long v[201]={0,};
long p[201]={0,};
long m[201]={0,};
long a[201][201]={0,};

void proc();

void refresh(){
	long i;
	for(i=1;i<=N;i++){
		v[i]=0;
	}
}

long min(long a,long b){
	if(a==0) return b;
	if(a>b) return b;
	return a;
}

long maxf(long a, long b){
	if(a<b) return b;
	return a;
}

long bfs(){
	refresh();
	queue<long> Q;
	Q.push(1);
	v[1]=1;
	long i;
	do{
		i=Q.front();
		Q.pop();
		for(long j=1;j<=N;j++){
			if(a[i][j]>0 && v[j]==0){
				p[j]=i;
				m[j]=min(m[i],a[i][j]);
				v[j]=1;
				if(j==N) return m[j];
				Q.push(j);

			}
		}
	}while(!Q.empty());
	return -1;
}

void all_re(){
	long i,j;
	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			a[i][j]=0;
		}
		v[i]=0;	p[i]=0;	m[i]=0;
	}
}
void input(){
	long M=0;
	long ga=0;
	//FILE *ipf=fopen("input.txt","r");
	while(scanf(/*ipf,*/"%d %d",&M,&N)!=EOF){
		all_re();
		long st, ar;
		long i;
		long max=0;
		for(i=1;i<=M;i++){
			/*f*/scanf(/*ipf,*/"%d %d %d",&st,&ar,&ga);
			a[st][ar]=ga;
			if(max<maxf(st,ar)) max=maxf(st,ar);
		}
		N=max;
		proc();	
	}
	/*fclose(ipf);*/
}

void proc(){
	long f=0;
	long path=N;
	long fun;
	fun=bfs();
	do{	
		if(fun==-1) break;
		f+=fun;
		path=N;
		do{
			
			a[p[path]][path]-=fun;
			a[path][p[path]]+=fun;
			path=p[path];
			if(p[path]==0) break;
			
		}while(1);
		fun=bfs();
		
	}while(1);
	//FILE *opf=fopen("output.txt","w");
	/*f*/printf(/*opf,*/"%d\n",f);
	//fclose(opf);
}

int main(){
	input();
	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