algo — C++23 日本語リファレンス GitHub

test/aoj/grl/min_cost_flow.test.cpp

AC · 最終更新 2026-07-24 · GitHub

問題: https://onlinejudge.u-aizu.ac.jp/problems/GRL_6_B

依存するヘッダ(2)
実装
// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/GRL_6_B
#include <iostream>
#include "flow/min_cost_flow.hpp"

int main(void) {
    int n, m, f;
    std::cin >> n >> m >> f;

    mcf_graph<int, int> mf(n);
    for (int i = 0; i < m; ++i) {
        int a, b, c, d;
        std::cin >> a >> b >> c >> d;
        mf.add_edge(a, b, c, d);
    }
    auto ans = mf.flow(0, n - 1, f);
    std::cout << (ans.first == f ? ans.second : -1) << '\n';

    return 0;
}