結果

問題 No.654 Air E869120
ユーザー e869120e869120
提出日時 2018-01-27 19:10:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,021 bytes
コンパイル時間 1,138 ms
コンパイル使用メモリ 88,704 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 10:00:14
合計ジャッジ時間 6,144 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct edge {
	long long to, cap, rev;
};

class Max_Flow {
public:
	vector<vector<edge>>X; vector<bool>used;
	void init(int size__) {
		X.resize(size__ + 2);
		used.resize(size__ + 2);
	}
	void add_edge(int u, int v, long long cap) {
		X[u].push_back(edge{ v,cap,(long long)X[v].size() });
		X[v].push_back(edge{ u,0LL,(long long)X[u].size() - 1 });
	}
	long long dfs(long long pos, long long to, long long cap) {
		if (pos == to) return cap;
		used[pos] = true;
		for (int i = 0; i < X[pos].size(); i++) {
			if (X[pos][i].cap <= 0 || used[X[pos][i].to] == true) continue;
			long long G = dfs(X[pos][i].to, to, min(X[pos][i].cap, cap));
			if (G <= 0) continue;
			X[pos][i].cap -= G;
			X[X[pos][i].to][X[pos][i].rev].cap += G;
			return G;
		}
		return 0;
	}
	long long max_flow(long long u, long long v) {
		long long E = 0;
		while (true) {
			for (int i = 0; i < used.size(); i++) used[i] = false;
			long long F = dfs(u, v, (1LL << 60));
			if (F == 0) break;
			E += F;
		}
		return E;
	}
};

long long n, m, p, a[1009], b[1009], c[1009], d[1009], e[1009]; vector<pair<long long, long long>>L;

int main() {
	cin >> n >> m >> p;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i]; d[i] += p;
		L.push_back(make_pair(a[i], c[i]));
		L.push_back(make_pair(b[i], d[i]));
	}
	sort(L.begin(), L.end()); Max_Flow X; X.init(L.size() + 4);
	for (int i = 0; i < m; i++) {
		int pos1 = lower_bound(L.begin(), L.end(), make_pair(a[i], c[i])) - L.begin();
		int pos2 = lower_bound(L.begin(), L.end(), make_pair(b[i], d[i])) - L.begin();
		X.add_edge(pos1, pos2, e[i]);
	}
	for (int i = 1; i < L.size(); i++) {
		if (L[i].first == L[i - 1].first) X.add_edge(i - 1, i, (1LL << 60));
	}
	for (int i = 0; i < L.size(); i++) {
		if (L[i].first == 1) X.add_edge(L.size(), i, (1LL << 60));
		if (L[i].first == n) X.add_edge(i, L.size() + 1, (1LL << 60));
	}
	cout << X.max_flow(L.size(), L.size() + 1) << endl;
	return 0;
}
0