結果

問題 No.654 Air E869120
ユーザー FF256grhyFF256grhy
提出日時 2018-02-24 00:03:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 3,019 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 175,192 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 12:01:02
合計ジャッジ時間 3,314 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename C> struct Flow {
	int V;
	C INF;
	struct E { int t, r; C c; };
	vector<vector<E>> g;
	vector<bool> used;
	
	Flow() { }
	Flow(int v, C inf) { init(v, inf); }
	void init(int v, C inf) {
		V = v;
		INF = inf;
		g.resize(V);
		used.resize(V);
	}
	
	void add(int f, int t, C c) {
		assert(inID(f, 0, V));
		assert(inID(t, 0, V));
		int gt = g[t].size();
		int gf = g[f].size();
		g[f].PB({ t, gt, c });
		g[t].PB({ f, gf, 0 });
	}
	
	C dfs(int f, int t, C c) {
		if(f == t) { return c; }
		used[f] = true;
		inc(i, g[f].size()) {
			E & e = g[f][i];
			if(used[e.t] || e.c <= 0) { continue; }
			C v = dfs(e.t, t, min(c, e.c));
			if(v > 0) {
				e.c -= v;
				g[e.t][e.r].c += v;
				return v;
			}
		}
		return 0;
	}
	
	C max_flow(int S, int T) {
		assert(inID(S, 0, V));
		assert(inID(T, 0, V));
		C ans = 0;
		while(true) {
			inc(i, V) { used[i] = false; }
			C f = dfs(S, T, INF);
			ans += f;
			if(f == 0) { break; }
		}
		return ans;
	}
};

// ----

const int M = 1000;
LL n, m, d, a[M], b[M], t[M], u[M], w[M];

int main() {
	cin >> n >> m >> d;
	inc(i, m) { cin >> a[i] >> b[i] >> t[i] >> u[i] >> w[i]; a[i]--; b[i]--; u[i] += d; }
	
	Flow<LL> f(m + 2, 1e10);
	int S = m;
	int T = S + 1;
	inc(i, m) {
		if(a[i] ==     0) { f.add(S, i, w[i]); }
		if(b[i] == n - 1) { f.add(i, T, w[i]); }
	}
	inc(i, m) {
	inc(j, m) {
		if(i == j) { continue; }
		if(b[i] == a[j] && u[i] <= t[j]) { f.add(i, j, min(w[i], w[j])); }
	}
	}
	
	cout << f.max_flow(S, T) << endl;
	
	return 0;
}
0