結果

問題 No.654 Air E869120
ユーザー kyawashellkyawashell
提出日時 2018-06-30 01:33:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 2,028 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 85,792 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 16:04:00
合計ジャッジ時間 2,808 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:92:17: 警告: ‘qq’ may be used uninitialized [-Wmaybe-uninitialized]
   92 |         add_edge(x[u[i]] + pp ,x[v[i]] + qq,w[i]);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:85:12: 備考: ‘qq’ はここで定義されています
   85 |         ll qq;
      |            ^~
main.cpp:92:17: 警告: ‘pp’ may be used uninitialized [-Wmaybe-uninitialized]
   92 |         add_edge(x[u[i]] + pp ,x[v[i]] + qq,w[i]);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:79:12: 備考: ‘pp’ はここで定義されています
   79 |         ll pp;
      |            ^~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

struct edge {
    ll to;
    ll cap;
    ll rev;
};

#define MAX_V 5000

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(ll from,ll to,ll cap) {
    G[from].push_back((edge){to,cap,(ll)G[to].size()});
    G[to].push_back((edge){from,0,(ll)G[from].size() - 1});
}

ll dfs(ll v,ll t,ll f) {
    if(v == t) return f;
    used[v] = true;
    rep(i,G[v].size()) {
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0) {
            ll d = dfs(e.to,t,min(e.cap,f));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(ll s,ll t) {
    ll flow = 0;
    for(;;) {
        fill(used,used+MAX_V,false);
        ll f = dfs(s,t,1e18);
        if(f == 0)break;
        flow += f;
    }
    return flow;
}
vector<ll> t[MAX_V];//頂点の飛行機が発着する時間
ll N,M,d,u[1001],v[1001],p[1001],q[1001],w[1001];
ll x[2000];

int main() {
    cin >> N >> M >> d;
    rep(i,M)cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i];

    rep(i,M){
        u[i]--;v[i]--;q[i]+=d;
        t[u[i]].push_back(p[i]);
        t[v[i]].push_back(q[i]);
    }
    t[0].push_back(0);
    t[N-1].push_back(2000000000);

    x[0] = 0;
    rep(i,N) {
        sort(t[i].begin(),t[i].end());
        t[i].erase(unique(t[i].begin(),t[i].end()),t[i].end());
        rep(j,(ll)t[i].size() - 1) {
            add_edge(x[i] + j,x[i] + j + 1,1e18);
        }
        x[i + 1] = x[i] + t[i].size();
    }

    rep(i,M) {
        ll pp;
        rep(j,t[u[i]].size()) {
            if(t[u[i]][j] == p[i]) {
                pp = j;
            }
        }
        ll qq;
        rep(j,t[v[i]].size()) {
            if(t[v[i]][j] == q[i]) {
                qq = j;
            }
        }

        add_edge(x[u[i]] + pp ,x[v[i]] + qq,w[i]);
    }

    cout << max_flow(0,x[N] - 1) << endl;
}
0