結果

問題 No.654 Air E869120
ユーザー sugarrrsugarrr
提出日時 2019-01-02 10:41:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 3,053 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 175,828 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-11 06:05:27
合計ジャッジ時間 3,692 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
//ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////
const long long inf = 1LL << 55;
#define MAX_V 2010//調節!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//辺を表す構造体{行き先、容量、逆辺}
struct edge{int to;ll cap;int rev;};
vector<edge> G[2009];
bool used[2009];//dfsですでに調べたかのフラグ
//fromからtoへの流量capの辺をグラフに追加
void add_edge(int from,int to,ll cap){
    G[from].push_back((edge){to,cap,(int)G[to].size()});
    G[to].push_back((edge){from,0LL,(int)G[from].size()-1});
}
//増加パスをdfsで探す
ll dfs(int v,int t,ll f){
    if(v==t)return f;
    used[v]=true;
    for(edge &e:G[v]){
        if(!used[e.to]&&e.cap>0){
            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(int s,int t){
    ll flow=0;
    while(1){
        memset(used,0,sizeof(used));
        ll f=dfs(s,t,inf);
        if(f==0)return flow;
        flow+=f;
    }
}
///////////////////////////////////////

int main(){
    int n,m,d;cin>>n>>m>>d;
    int u[MAX_V],v[MAX_V],p[MAX_V],q[MAX_V],w[MAX_V];
    vector<int>t[MAX_V];
    int ps[MAX_V];
    rep(i,0,m-1){
        cin>>u[i]>>v[i]>>p[i]>>q[i]>>w[i];
        u[i]--;v[i]--;
        q[i]+=d;
        t[u[i]].pb(p[i]);
        t[v[i]].pb(q[i]);
    }
    
    /*rep(i,0,n-1){
        sort(t[i].begin(),t[i].end());
        t[i].erase(unique(t[i].begin(),t[i].end()),t[i].end());
        ps[i+1]=ps[i]+t[i].size();
    }
    rep(i,0,n-1){
        int ca=t[i].size();
        if(ca<=1)continue;
        rep(j,0,ca-2){
            add_edge(ps[i]+j,ps[i]+j+1,inf);
        }
    }
    */
    rep(i,0,n-1){
        sort(t[i].begin(),t[i].end());
        t[i].erase(unique(t[i].begin(),t[i].end()),t[i].end());
        ps[i+1]=ps[i]+t[i].size();
    }
    rep(i,0,n-1){
        int ca=t[i].size();
        if(ca<=1)continue;
        rep(j,0,ca-2){
            add_edge(ps[i]+j,ps[i]+j+1,inf);
        }
    }
    
    
    rep(i,0,m-1){
        int paa=ps[u[i]]+lower_bound(t[u[i]].begin(),t[u[i]].end(),p[i])-t[u[i]].begin();
        int pbb=ps[v[i]]+lower_bound(t[v[i]].begin(),t[v[i]].end(),q[i])-t[v[i]].begin();
        add_edge(paa,pbb,w[i]);
    }
    int V=ps[n];
    ll ans=max_flow(0,V-1);
    cout<<ans<<endl;
    
    return 0;
}

0