結果

問題 No.654 Air E869120
ユーザー kura197kura197
提出日時 2021-07-03 16:05:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,194 bytes
コンパイル時間 2,920 ms
コンパイル使用メモリ 224,012 KB
実行使用メモリ 8,120 KB
最終ジャッジ日時 2023-09-12 20:43:20
合計ジャッジ時間 7,668 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,120 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 70 ms
4,376 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 AC 40 ms
4,380 KB
testcase_13 AC 64 ms
4,380 KB
testcase_14 AC 27 ms
4,380 KB
testcase_15 AC 31 ms
4,376 KB
testcase_16 AC 526 ms
4,384 KB
testcase_17 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

ll V;
const ll INF = 1LL << 60;
const int MAX_V = 2100;

using P = pair<ll, ll>;

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

struct edge { int to, rev; long long cap; };
vector<edge> g[2009];
bool vis[2009];
const long long inf = 1LL << 55;

////// G に辺と逆辺を追加
//void add_edge(int from, int to, ll cap){
//    G[from].push_back(Edge(to, cap, G[to].size()));
//    G[to].push_back(Edge(from, 0, G[from].size()-1));
//}
//
////// 増加パスをdfsで探索
////ll find_path(int v, int t, ll f, auto& used){
//ll find_path(int v, int t, ll f){
//    if(v == t) return f;
//    used[v] = true;
//    for(auto& [to, cap, rev] : G[v]){
//        if(!used[to] && cap > 0){
//            //ll d = find_path(to, t, min(f, cap), used);
//            ll d = find_path(to, t, min(f, cap));
//            if(d > 0){
//                cap -= d;
//                get<1>(G[to][rev]) += d;
//                return d;
//            }
//        }
//    }
//    return 0; 
//}
//
////// sからtへの最大流を求める
//ll max_flow(int s, int t){
//    ll flow = 0;
//    //array<bool, MAX_V> used;
//    while(1){
//        //fill(used.begin(), used.end(), false);
//        fill(used, used+V, false);
//        //ll f = find_path(s, t, INF, used);
//        ll f = find_path(s, t, INF);
//        if(f == 0) break;
//        flow += f;
//    }
//    return flow;
//}

void add_edge(int v1, int v2, long long cost) {
    g[v1].push_back(edge{ v2, (int)g[v2].size(), cost });
    g[v2].push_back(edge{ v1, (int)g[v1].size() - 1, 0LL });
}
long long find_augment(int pos, int tar, long long curflow) {
    if (pos == tar) return curflow;
    vis[pos] = true;
    for (edge &e : g[pos]) {
        if (!vis[e.to] && e.cap > 0) {
            long long newflow = find_augment(e.to, tar, min(e.cap, curflow));
            if (newflow > 0) {
                e.cap -= newflow;
                g[e.to][e.rev].cap += newflow;
                return newflow;
            }
        }
    }
    return 0;
}
long long max_flow(int src, int dst) {
    long long ret = 0;
    while (true) {
        fill(vis, vis + V, false);
        long long res = find_augment(src, dst, inf);
        if (res == 0) break;
        ret += res;
    }
    return ret;
}

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;
        scanf("%lld %lld %lld %lld %lld", &u, &v, &p, &q, &w);
        u--, v--;
        X.push_back(T(u, v, p, q, w));
    }

    vector<vector<int>> vertex(N);
    vertex[0].push_back(0);
    vertex[N-1].push_back(1000000000LL);

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

    map<P, int> pos2idx;
    ll cnt = 0;
    REP(v, N){
        sort(vertex[v].begin(), vertex[v].end());
        vertex[v].erase(unique(vertex[v].begin(), vertex[v].end()), vertex[v].end());
        int size = vertex[v].size();
        REP(i, size){
            pos2idx[P(v, vertex[v][i])] = cnt++;
        }
    }

    for(auto& [u, v, p, q, w] : X){
        auto v0 = pos2idx[P(u, p)];
        auto v1 = pos2idx[P(v, q+D)];
        add_edge(v0, v1, w);
    }

    REP(v, N){
        int size = vertex[v].size();
        REP(i, size-1){
            auto v0 = pos2idx[P(v, vertex[v][i])];
            auto v1 = pos2idx[P(v, vertex[v][i+1])];
            add_edge(v0, v1, INF);
        }
    }

    V = cnt;
    //cout << V << endl;

    ll ans = max_flow(0, cnt-1);
    cout << ans << endl;
    return 0;
}
0