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

有大神帮忙看一看么 为啥就是tle 别的人和我写的差不多都能过,心好累

Posted by nankeyimeng at 2017-08-06 11:21:17 on Problem 1459
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#define ll long long
#define read(a) scanf("%d",&a);
using namespace std;
const int maxn=105;
const int inf=99999999;
int c[maxn][maxn];
bool book[maxn];
int pre[maxn];
int main(){
	//freopen("test.txt","r",stdin);
	int n,np,nc,m;
	char c1,c2,c3;
	//int i,j;
	int ans;
	int mini;
	int first,second,third;
	char temp[20];
	int num;
	//while(cin>>n>>np>>nc>>m){
	while(~scanf("%d %d %d %d",&n,&np,&nc,&m)){
		memset(c,0,sizeof(c));
		n++;
		for(int i=0;i<m;i++){
			scanf("%s",temp);sscanf(temp,"(%d,%d)%d",&first,&second,&third);
			first++;second++;
			c[first][second]+=third;
		}
		for(int i=0;i<np;i++){
			scanf("%s",temp);sscanf(temp,"(%d)%d",&first,&second);
			first++;
			c[0][first]+=second;
		}
		for(int i=0;i<nc;i++){
			scanf("%s",temp);sscanf(temp,"(%d)%d",&first,&second);
			first++;
			c[first][n]+=second;
		}
		ans=0;
		while(1){
			for(int i=0;i<=n;i++){
				book[i]=false;
				pre[i]=-1;
			}
			queue<int>q;
			mini=inf;
			q.push(0);
			book[0]=true;
			while(!q.empty()){
				num=q.front();
				q.pop();
				if(book[n])
					break;
				for(int i=0;i<=n;i++){
					if(book[i]==false&&c[num][i]>0){
						book[i]=true;
						pre[i]=num;
						mini=min(mini,c[num][i]);
						q.push(i);
					}
				}
			}
			if(!book[n])
				break;
			ans+=mini;
			int tmp=n;
			while(pre[tmp]!=-1){
				c[pre[tmp]][tmp]-=mini;
				c[tmp][pre[tmp]]+=mini;
				tmp=pre[tmp];
			}
		}
		printf("%d\n",ans);
	}
	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