結果

問題 No.654 Air E869120
ユーザー square1001square1001
提出日時 2018-01-28 16:48:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,758 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 83,064 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-28 13:07:44
合計ジャッジ時間 2,737 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge { int to, cap, rev; };
const int inf = 1012345678;
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, int cost) {
	g[v1].push_back(edge{ v2, cost, (int)g[v2].size() });
	g[v2].push_back(edge{ v1, 0, (int)g[v1].size() - 1 });
}
int find_augment(int pos, int tar, int curflow) {
	if (pos == tar) return curflow;
	vis[pos] = true;
	for (edge &e : g[pos]) {
		if (!vis[e.to] && e.cap > 0) {
			int 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;
}
int max_flow(int src, int dst) {
	int ret = 0;
	while (true) {
		fill(vis, vis + V, false);
		int 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] = { inf };
	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];
	int ret = max_flow(0, V - 1);
	cout << ret << '\n';
	return 0;
}
0