結果

問題 No.654 Air E869120
ユーザー Kana NagataKana Nagata
提出日時 2019-06-12 23:12:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,257 bytes
コンパイル時間 3,837 ms
コンパイル使用メモリ 202,572 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-02 05:14:35
合計ジャッジ時間 4,426 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<typename T>
class fixed_point : T {
  public:
    explicit constexpr fixed_point (
        T&& t
      ) noexcept
      : T(forward<T>(t))
      {
      }
    template<typename... Args>
    constexpr decltype(auto)
    operator()(
        Args&&... args
      ) const
      {
        return T::operator()(*this, forward<Args>(args)...);
      }
};
template<typename T>
static inline constexpr decltype(auto) fix (T&& t) noexcept {
  return fixed_point<T>{forward<T>(t)};
}
template <typename T>
class dinic {
  struct edge {
    int to; T cap;
    weak_ptr<edge> rev;
  };
  const int n, source, sink;
  vector<bool> ckd;
  vector<int> dst;
  vector<vector<shared_ptr<edge>>> grh;
  public: static constexpr T inf = numeric_limits<T>::max();
  private:
  void bfs () {
    queue<int> que;
    que.emplace(source); dst[source] = 0;
    while (!que.empty()) {
      int crr = que.front(); que.pop();
      for (auto const& e : grh[crr]) {
        if (e->cap == 0) continue;
        int nxt = e->to;
        if (dst[nxt] != -1) continue;
        que.push(nxt); dst[nxt] = dst[crr] + 1;
      }
    }
  }
  T dfs () {
    return fix ([&](auto dfs, int crr, int f = inf) -> T {
      if (crr == sink) return f;
      ckd[crr] = true;
      for (auto& e : grh[crr]) {
        int nxt = e->to;
        if (ckd[nxt] || e->cap == 0 || dst[crr] >= dst[nxt]) continue;
        T d = dfs(nxt, min(f, e->cap));
        if (d > 0) {
          e->cap -= d;
          e->rev.lock()->cap += d;
          return d;
        }
      }
      dst[crr] = -1;
      return 0;
    })(source);
  }
  public:
    dinic (int n, int source, int sink) :
      n(n), source(source), sink(sink), grh(n)
      {}
    void insert(int u, int v, T c) {
      auto e = make_shared<edge>(edge{v, c});
      auto r = make_shared<edge>(edge{u, 0});
      e->rev = r;
      r->rev = e;
      grh[u].push_back(e);
      grh[v].push_back(r);
    }
    T cal() {
      T ret = 0;
      while (true) {
        dst.assign(n, -1);
        bfs();
        if (dst[sink] == -1) return ret;
        ckd.assign(n, false);
        while (true) {
          T f = dfs();
          if (f == 0) break;
          ret += f;
        }
      }
    }
};
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, m, d;
  cin >> n >> m >> d;
  vector<pair<int, int>> vtx(n);
  vtx.emplace_back(0, -d);
  vtx.emplace_back(n - 1, 1e9);
  vector<tuple<int, int, int, int, int>> query;
  while (m--) {
    int u, v, p, q, w;
    cin >> u >> v >> p >> q >> w;
    u--; v--;
    query.emplace_back(u, v, p, q, w);
    vtx.emplace_back(u, p - d);
    vtx.emplace_back(v, q);
  }
  sort(vtx.begin(), vtx.end());
  int N = unique(vtx.begin(), vtx.end()) - vtx.begin();
  vtx.resize(N);
  dinic<int> dnc(N, 0, N - 1);
  for (int i = 0; i < N - 1; i++) {
    if (vtx[i].first == vtx[i + 1].first) dnc.insert(i, i + 1, dinic<int>::inf);
  }
  for (auto const& qry : query) {
    int u, v, p, q, w; tie(u, v, p, q, w) = qry;
    int s = find(vtx.begin(), vtx.end(), pair<int, int>{u, p - d}) - vtx.begin();
    int t = find(vtx.begin(), vtx.end(), pair<int, int>{v, q}) - vtx.begin();
    dnc.insert(s, t, w);
  }
  int ret = dnc.cal();
  cout << ret << endl;
  return 0;
}
0