結果

問題 No.654 Air E869120
ユーザー kura197kura197
提出日時 2021-07-03 15:20:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,752 bytes
コンパイル時間 3,697 ms
コンパイル使用メモリ 232,488 KB
実行使用メモリ 8,880 KB
最終ジャッジ日時 2023-09-12 19:49:59
合計ジャッジ時間 13,076 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,880 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,504 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:34:30: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   34 | ll find_path(P v, P t, ll f, auto& used){
      |                              ^~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

const ll INF = 1LL << 60;
const int MAX_V = 1100;

using P = pair<ll, ll>;

//// {行き先, 容量, 逆辺}
//// {to, cap, rev}
//// G[v][to] <-> G[to][rev]
using Edge = tuple<P, ll, ll>;
unordered_map<ll, vector<Edge>> G[1100];

//// G に辺と逆辺を追加
void add_edge(P from, P to, ll cap){
    G[from.first][from.second].push_back(Edge(to, cap, G[to.first][to.second].size()));
    G[to.first][to.second].push_back(Edge(from, 0, G[from.first][from.second].size()-1));
}

//// 増加パスをdfsで探索
ll find_path(P v, P t, ll f, auto& used){
    if(v == t) return f;
    used[v.first].insert(v.second);
    for(auto& [to, cap, rev] : G[v.first][v.second]){
        if(used[to.first].find(to.second) == used[to.first].end() && cap > 0){
            ll d = find_path(to, t, min(f, cap), used);
            if(d > 0){
                cap -= d;
                get<1>(G[to.first][to.second][rev]) += d;
                return d;
            }
        }
    }
    return 0; 
}

//// sからtへの最大流を求める
ll max_flow(P s, P t){
    ll flow = 0;
    while(1){
        vector<unordered_set<ll>> used(MAX_V);
        ll f = find_path(s, t, INF, used);
        if(f == 0) break;
        flow += f;
    }
    return flow;
}

int main(){
    ll N, M, D;
    cin >> N >> M >> D;
    using T = tuple<ll, ll, ll, ll, ll>;
    vector<T> X;
    REP(i,M){
        ll u, v, p, q, w;
        cin >> u >> v >> p >> q >> w;
        u--, v--;
        if(q+D > 1000000000LL)
            continue;
        X.push_back(T(u, v, p, q, w));
    }

    vector<set<int>> vertex(N);

    for(auto& [u, v, p, q, w] : X){
        vertex[u].insert(p);
        vertex[v].insert(q+D);
        add_edge(P(u, p), P(v, q+D), w);
        //add_edge(P(u, p), P(v, q), w);
    }

    REP(v, N){
        auto vec = vector<int>(vertex[v].begin(), vertex[v].end());
        int size = vec.size();
        REP(i,size){
            REPi(j,i+1,size){
                add_edge(P(v, vec[i]), P(v, vec[j]), INF);
            }
        }
    }

    if(vertex[0].size() == 0 || vertex[N-1].size() == 0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = max_flow(P(0, *vertex[0].begin()), P(N-1, *prev(vertex[N-1].end(), 1)));
    cout << ans << endl;
    return 0;
}
0