結果

問題 No.654 Air E869120
ユーザー square1001square1001
提出日時 2018-01-28 16:53:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,830 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 13:08:02
合計ジャッジ時間 2,533 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge { int to, rev; long long cap; };
const long long inf = 1LL << 55;
int N, M, V, d, a[1009], b[1009], p[1009], q[1009], w[1009], ps[1009]; bool vis[2009]; vector<int> t[1009]; vector<edge> g[2009];
void add_edge(int v1, int v2, long long cost) {
	g[v1].push_back(edge{ v2, (int)g[v2].size(), cost });
	g[v2].push_back(edge{ v1, (int)g[v1].size() - 1, 0LL });
}
long long find_augment(int pos, int tar, long long curflow) {
	if (pos == tar) return curflow;
	vis[pos] = true;
	for (edge &e : g[pos]) {
		if (!vis[e.to] && e.cap > 0) {
			long long newflow = find_augment(e.to, tar, min(e.cap, curflow));
			if (newflow > 0) {
				e.cap -= newflow;
				g[e.to][e.rev].cap += newflow;
				return newflow;
			}
		}
	}
	return 0;
}
long long max_flow(int src, int dst) {
	long long ret = 0;
	while (true) {
		fill(vis, vis + V, false);
		long long res = find_augment(src, dst, inf);
		if (res == 0) break;
		ret += res;
	}
	return ret;
}
int main() {
	cin >> N >> M >> d;
	t[0] = { 0 }; t[N - 1] = { 1012345678 };
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> p[i] >> q[i] >> w[i];
		t[--a[i]].push_back(p[i]);
		t[--b[i]].push_back(q[i] + d);
	}
	for (int i = 0; i < N; i++) {
		sort(t[i].begin(), t[i].end());
		t[i].erase(unique(t[i].begin(), t[i].end()), t[i].end());
		ps[i + 1] = ps[i] + t[i].size();
		for (int j = ps[i]; j < ps[i + 1] - 1; j++) {
			add_edge(j, j + 1, inf);
		}
	}
	for (int i = 0; i < M; i++) {
		int pa = lower_bound(t[a[i]].begin(), t[a[i]].end(), p[i]) - t[a[i]].begin() + ps[a[i]];
		int pb = lower_bound(t[b[i]].begin(), t[b[i]].end(), q[i] + d) - t[b[i]].begin() + ps[b[i]];
		add_edge(pa, pb, w[i]);
	}
	V = ps[N];
	long long ret = max_flow(0, V - 1);
	cout << ret << '\n';
	return 0;
}
0