結果
問題 | No.654 Air E869120 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-01-24 11:27:02 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 4,077 bytes |
コンパイル時間 | 1,123 ms |
コンパイル使用メモリ | 127,616 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-13 03:36:28 |
合計ジャッジ時間 | 2,880 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 15 ms
6,940 KB |
testcase_11 | AC | 14 ms
6,940 KB |
testcase_12 | AC | 12 ms
6,940 KB |
testcase_13 | AC | 13 ms
6,940 KB |
testcase_14 | AC | 14 ms
6,944 KB |
testcase_15 | AC | 13 ms
6,940 KB |
testcase_16 | AC | 24 ms
6,944 KB |
testcase_17 | AC | 27 ms
6,940 KB |
testcase_18 | AC | 24 ms
6,940 KB |
testcase_19 | AC | 25 ms
6,940 KB |
testcase_20 | AC | 10 ms
6,944 KB |
testcase_21 | AC | 11 ms
6,940 KB |
testcase_22 | AC | 6 ms
6,940 KB |
testcase_23 | AC | 8 ms
6,940 KB |
testcase_24 | AC | 11 ms
6,940 KB |
testcase_25 | AC | 6 ms
6,940 KB |
testcase_26 | AC | 7 ms
6,940 KB |
testcase_27 | AC | 5 ms
6,940 KB |
testcase_28 | AC | 6 ms
6,940 KB |
testcase_29 | AC | 5 ms
6,940 KB |
testcase_30 | AC | 6 ms
6,944 KB |
testcase_31 | AC | 6 ms
6,940 KB |
testcase_32 | AC | 7 ms
6,940 KB |
testcase_33 | AC | 6 ms
6,940 KB |
testcase_34 | AC | 7 ms
6,940 KB |
testcase_35 | AC | 1 ms
6,944 KB |
testcase_36 | AC | 1 ms
6,944 KB |
testcase_37 | AC | 1 ms
6,944 KB |
testcase_38 | AC | 1 ms
6,940 KB |
testcase_39 | AC | 1 ms
6,940 KB |
ソースコード
import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); } class MaxFlow(Capa) { enum Capa wEPS = 0; enum Capa wINF = 10L^^18; int n, m; int[][] g; int[] zu; Capa[] capa; Capa tof; int[] lev, see, que; this(int n) { this.n = n; m = 0; g = new int[][n]; zu = []; capa = []; lev = new int[n]; see = new int[n]; que = new int[n]; } void addEdge(int u, int v, Capa w0, Capa w1 = 0) { g[u] ~= m; zu ~= v; capa ~= w0; ++m; g[v] ~= m; zu ~= u; capa ~= w1; ++m; } Capa augment(int src, int ink, Capa flo) { if (src == ink) return flo; foreach (i; g[src][see[src] .. $]) { if (capa[i] > wEPS && lev[src] < lev[zu[i]]) { Capa f = augment(zu[i], ink, min(flo, capa[i])); if (f > wEPS) { capa[i] -= f; capa[i ^ 1] += f; return f; } } ++see[src]; } return 0; } bool dinic(int src, int ink, Capa flo = wINF) { for (tof = 0; tof + wEPS < flo; ) { int[] q; lev[] = -1; dinicBFS: for (lev[src] = 0, q ~= src; !q.empty; ) { int u = q.front; q.popFront; foreach (i; g[u]) { int v = zu[i]; if (capa[i] > wEPS && lev[v] == -1) { lev[v] = lev[u] + 1; q ~= v; if (v == ink) break dinicBFS; } } } if (lev[ink] == -1) return false; see[] = 0; for (; ; ) { Capa f = augment(src, ink, flo - tof); if (f <= wEPS) break; tof += f; } } return true; } } enum LIM = 2 * 10L^^9; int N, M; long D; int[] A, B; long[] P, Q, W; void main() { try { for (; ; ) { N = readInt(); M = readInt(); D = readLong(); A = new int[M]; B = new int[M]; P = new long[M]; Q = new long[M]; W = new long[M]; foreach (i; 0 .. M) { A[i] = readInt() - 1; B[i] = readInt() - 1; P[i] = readLong(); Q[i] = readLong(); W[i] = readLong(); } auto tss = new long[][N]; foreach (i; 0 .. M) { tss[A[i]] ~= P[i]; tss[B[i]] ~= Q[i] + D; } foreach (u; 0 .. N) { tss[u] ~= 0; tss[u] ~= LIM; tss[u] = tss[u].sort.uniq.array; debug { writeln(u, " ", tss[u]); } } int V; auto ids = new int[][N]; foreach (u; 0 .. N) { ids[u] = new int[tss[u].length]; foreach (x; 0 .. tss[u].length) { ids[u][x] = V++; } } auto mf = new MaxFlow!long(V); foreach (u; 0 .. N) { foreach (x; 1 .. tss[u].length) { mf.addEdge(ids[u][x - 1], ids[u][x], MaxFlow!long.wINF); } } foreach (i; 0 .. M) { const u = A[i]; const v = B[i]; const x = tss[u].lowerBound(P[i]); const y = tss[v].lowerBound(Q[i] + D); mf.addEdge(ids[u][x], ids[v][y], W[i]); } mf.dinic(ids[0][0], ids[N - 1][$ - 1]); writeln(mf.tof); } } catch (EOFException e) { } }