結果

問題 No.654 Air E869120
ユーザー 193s193s
提出日時 2018-02-25 20:42:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,782 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 118,848 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 02:22:40
合計ジャッジ時間 2,293 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 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 2 ms
6,944 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 5 ms
6,944 KB
testcase_15 AC 6 ms
6,940 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 2 ms
6,944 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define MAX_V 2010
struct Dinic {
  struct Edge { int to, cap, rev; };
  vector<Edge> G[MAX_V];
  int level[MAX_V], iter[MAX_V];
  void add_edge(int from, int to, int cap) {
    G[from].pb((Edge) { to, cap, (int)G[to].size() });
    G[to].pb((Edge) { from, 0, (int)G[from].size()-1 });
  }
  void bfs(int s) {
    rep(i, MAX_V) level[i] = INF;
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (Edge e : G[x]) if (e.cap > 0 && level[e.to] == INF) {
        level[e.to] = level[x]+1;
        q.push(e.to);
      }
    }
  }
  int dfs(int x, int goal, int f) {
    if (x == goal) return f;
    for (int &i=iter[x]; i<G[x].size(); i++) {
      Edge &e = G[x][i];
      if (e.cap > 0 && level[x] < level[e.to]) {
        int w = dfs(e.to, goal, min(f, e.cap));
        if (w > 0) {
          e.cap -= w;
          G[e.to][e.rev].cap += w;
          return w;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] == INF) return flow;
      rep(i, MAX_V) iter[i] = 0;
      while (true) {
        int f = dfs(s, t, INF);
        if (f == 0) break;
        flow += f;
      }
    }
  }
};

int N, M, D;
int base[1000];
vector<int> W[1000];
Dinic dinic;
int V;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M >> D;
  vector<tuple<int, int, int, int, int> > edges;
  rep(i, M) {
    int u, v, p, q, w;
    cin >> u >> v >> p >> q >> w;
    u--, v--;
    q += D;
    W[u].pb(p);
    W[v].pb(q);
    edges.pb(make_tuple(u, v, p, q, w));
  }
  if (W[N-1].empty() || W[0].empty()) {
    cout << 0 << "\n";
    return 0;
  }
  rep(x, N) {
    sort(all(W[x])), uniq(W[x]);
    base[x] = V;
    rep(i, (int)W[x].size()-1) {
      dinic.add_edge(base[x]+i, base[x]+i+1, INF);
    }
    V += W[x].size();
  }
  int s = V++, t = V++;
  dinic.add_edge(s, base[0], INF);
  dinic.add_edge(base[N-1]+(int)W[N-1].size()-1, t, INF);
  for (auto pp : edges) {
    int u, v, p, q, w; tie(u, v, p, q, w) = pp;
    dinic.add_edge(base[u]+index(W[u], p), base[v]+index(W[v], q), w);
  }
  cout << dinic.max_flow(s, t) << "\n";
  return 0;
}
0