记录编号 396028 评测结果 A
题目名称 Blue Mary的旅行 最终得分 100
用户昵称 GravatarHeHe 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2017-04-17 20:59:38 内存使用 0.32 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

const int MAXN = 200;
const int INF = 0x7fffffff;

inline int in(void){ 
	char tmp = getchar();
	int res = 0;
	while(!isdigit(tmp))tmp = getchar();
	while(isdigit(tmp))
		res = (res + (res << 2) << 1) + (tmp ^ 48),
		tmp = getchar();
	//printf("read\n");
	return res;
}

struct EDGE{ 
	int fr, to, ne;
	int cap;

	EDGE(){;}
	EDGE(int a, int b, int c, int d){ 
		fr = a, to = b, ne = c;
		cap = d;
	}
};

inline void add_edge(int fr, int to, int cap);
bool BFS(void);
inline int get_flow(void);

vector<EDGE> edge;
int head[MAXN], pre[MAXN];
int S, T, max_flow;
int N, M, t;

int main(){ 
#ifndef LOCAL
	freopen("btravel.in", "r", stdin);
	freopen("btravel.out", "w", stdout);
#else
	freopen("test.in", "r", stdin);
#endif
	memset(head, 0xff, sizeof(head));

	N = in(), M = in(), t = in();
	//printf("%d %d %d\n", N, M, t);
	S = 1, T = N;
	for(int i = 1, a, b, c; i <= M; ++i){ 
		a = in(), b = in(), c = in();
		add_edge(a, b, c);
		//printf("Read End\n");
	}
	//printf("Reading End\n");

	while(BFS()){ 
		max_flow += get_flow();
	}

	//printf("max_flow = %d\n", max_flow);
	printf("%d\n", (t + (max_flow - 1))/max_flow + 1);

	return 0;
}

inline void add_edge(int fr, int to, int cap){ 
	edge.push_back(EDGE(fr, to, head[fr], cap)), head[fr] = edge.size() - 1;
	edge.push_back(EDGE(to, fr, head[to], 0)), head[to] = edge.size() - 1;
	return ;
}

bool BFS(void){ 
	static bool vis[MAXN];
	static queue<int> que;
	static int now, to;

	memset(vis, 0x00, sizeof(vis));
	memset(pre, 0xff, sizeof(pre));
	while(!que.empty())que.pop();

	que.push(S);
	vis[S] = true;

	while(!que.empty()){ 
		now = que.front();
		que.pop();
		if(now == T)return true;

		for(int i = head[now]; ~i; i = edge[i].ne){ 
			if(!edge[i].cap || vis[to = edge[i].to])continue;
			que.push(to);
			vis[to] = true;
			pre[to] = i;
		}
	}

	return false;
}

inline int get_flow(void){ 
	int now = pre[T], min_flow = INF;
	while(~now){ 
		min_flow = min(min_flow, edge[now].cap);
		now = pre[edge[now].fr];
	}

	now = pre[T];
	while(~now){ 
		edge[now].cap -= min_flow;
		edge[now ^ 1].cap += min_flow;
		now = pre[edge[now].fr];
	}

	return min_flow;
}