結果

問題 No.654 Air E869120
ユーザー kuhaku
提出日時 2020-08-19 03:16:16
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,432 bytes
コンパイル時間 9,254 ms
コンパイル使用メモリ 272,812 KB
最終ジャッジ日時 2025-01-13 03:39:36
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 25 WA * 6 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9+7;

using Graph = map<P, map<P, ll>>;
set<P> used;
Graph graph;

ll dfs(P v, ll t, ll f){
	cerr << v.first << " " << v.second << endl;
	if (v.first == t) return f;
	auto p = graph.lower_bound(v);
	while(p->first.first == v.first){
		for(auto &q : p->second){
			if (used.find(q.first) == used.end() && q.second) {
				used.insert(q.first);
				ll d = dfs(q.first, t, min(f, q.second));
				if (d) {
					q.second -= d;
					graph[q.first][v] += d;
					return d;
				}
			}
		}
		++p;
	}
	return 0;
}

// 最大流を求める
ll ford_fulkerson(ll s, ll t){
	ll res = 0;
	while(true){
		used.clear();
		ll f = dfs({s, 0}, t, LINF);
		cerr << f << endl;
		if (!f) break;
		res += f;
	}
	return res;
}

int main(void) {
	ll V, E, d;
	cin >> V >> E >> d;
	rep(i, E){
		ll u, v, p, q, w;
		cin >> u >> v >> p >> q >> w;
		--u, --v, q += d;
		graph[{u, p}][{v, q}] = w;
	}
	cout << ford_fulkerson(0, V - 1) << endl;

	return 0;
}
0