結果

問題 No.654 Air E869120
ユーザー planesplanes
提出日時 2022-03-30 01:03:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,852 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 189,136 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-26 10:00:14
合計ジャッジ時間 3,242 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)


ll INF=2e16;

struct edge {ll to,cap,rev;};
ll V;
vector<vector<edge>> G;
vector<ll> level;
vector<ll> iter;


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

void bfs(ll s) {
    level=vector<ll> (V,-1);

    queue<ll> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()) {
        ll v=que.front();
        que.pop();
        for(ll i=0;i<G[v].size();i++) {
            edge &e=G[v][i];
            if(e.cap>0&&level[e.to]<0) {
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}


ll dfs(ll v,ll t,ll f) {
    if(v==t) return f;
    for(ll &i=iter[v];i<G[v].size();i++) {
        edge &e=G[v][i];
        if(e.cap>0&&level[v]<level[e.to]) {
            ll d=dfs(e.to,t,min(f,e.cap));
            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(;;) {
        bfs(s);
        if(level[t]<0) return flow;
       iter=vector<ll> (V,0);
        ll f;
        while((f=dfs(s,t,INF))>0) {
            flow+=f;
        }
    }
}



int main() {
    ll N,M,d;cin>>N>>M>>d;
    vector<vector<ll>> t(N,vector<ll> (0));
  vector<ll> u(M);
  vector<ll> v(M);
  vector<ll> p(M);
  vector<ll> q(M);
  vector<ll> w(M);

    for(ll i=0;i<M;i++) {
      cin>>u[i]>>v[i]>>p[i]>>q[i]>>w[i];
        u[i]--;v[i]--;
        t[u[i]].push_back(p[i]);
        t[v[i]].push_back(q[i]+d);
    }



    for(ll i=0;i<N;i++) sort(all(t[i]));

vector<vector<pair<ll,ll>>> note(N,vector<pair<ll,ll>> (0));

ll count=0;

    for(ll i=0;i<N;i++) {
        vector<ll> num(0);
        ll now=-1;
        for(auto x:t[i]) {
            if(now!=x) {
                now=x;
                num.push_back(now);
            }
        }

        for(auto x:num) {
            note[i].push_back({x,count});
            count++;
        }
    }



    V=count;
    G=vector<vector<edge>> (V,vector<edge> (0));

    for(ll i=0;i<N;i++) {
        for(ll j=0;j<(ll)note[i].size()-1;j++) {
            add_edge(note[i][j].second,note[i][j+1].second,INF);
        }
    }

    for(ll i=0;i<M;i++) {
        ll ind1=lower_bound(all(note[u[i]]),make_pair(p[i],0LL))-note[u[i]].begin();
        ll ind2=lower_bound(all(note[v[i]]),make_pair(q[i]+d,0LL))-note[v[i]].begin();

        add_edge(note[u[i]][ind1].second,note[v[i]][ind2].second,w[i]);
    }

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

    


    



0