結果

問題 No.654 Air E869120
ユーザー sugarrrsugarrr
提出日時 2019-01-02 10:51:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,796 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 181,772 KB
実行使用メモリ 89,672 KB
最終ジャッジ日時 2024-04-28 23:17:12
合計ジャッジ時間 7,639 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
27,820 KB
testcase_01 AC 12 ms
27,892 KB
testcase_02 AC 13 ms
27,716 KB
testcase_03 AC 11 ms
27,904 KB
testcase_04 AC 12 ms
27,984 KB
testcase_05 AC 12 ms
27,904 KB
testcase_06 AC 12 ms
27,968 KB
testcase_07 AC 11 ms
27,716 KB
testcase_08 AC 12 ms
27,776 KB
testcase_09 AC 13 ms
27,844 KB
testcase_10 AC 45 ms
28,072 KB
testcase_11 AC 33 ms
28,096 KB
testcase_12 AC 30 ms
28,288 KB
testcase_13 AC 31 ms
27,976 KB
testcase_14 AC 26 ms
28,172 KB
testcase_15 AC 29 ms
28,032 KB
testcase_16 AC 26 ms
28,116 KB
testcase_17 AC 26 ms
28,192 KB
testcase_18 AC 22 ms
28,160 KB
testcase_19 AC 28 ms
28,232 KB
testcase_20 AC 16 ms
28,232 KB
testcase_21 AC 17 ms
28,288 KB
testcase_22 AC 16 ms
28,268 KB
testcase_23 AC 16 ms
28,288 KB
testcase_24 AC 17 ms
28,264 KB
testcase_25 AC 15 ms
28,100 KB
testcase_26 AC 15 ms
28,260 KB
testcase_27 AC 15 ms
28,084 KB
testcase_28 AC 16 ms
28,232 KB
testcase_29 AC 15 ms
28,284 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 11 ms
27,904 KB
testcase_36 AC 12 ms
27,976 KB
testcase_37 AC 11 ms
27,860 KB
testcase_38 RE -
testcase_39 AC 13 ms
27,880 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;
////////////////////////////////////////
//int inf=(int)1E7;
#define MAX_V 1000000//調節!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//辺を表す構造体{行き先、容量、逆辺}
struct edge{ll to,cap,rev;};
vector<edge> G[MAX_V];
bool used[MAX_V];//dfsですでに調べたかのフラグ
//fromからtoへの流量capの辺をグラフに追加
void add_edge(ll from,ll to,ll cap){
    G[from].push_back((edge){to,cap,static_cast<ll>(G[to].size())});
    G[to].push_back((edge){from,0,static_cast<ll>(G[from].size()-1)});
}
//増加パスをdfsで探す
ll dfs(ll v,ll t,ll f){
    if(v==t)return f;
    used[v]=true;
    for(ll i=0;i<G[v].size();i++){
        edge &e=G[v][i];
        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(ll s,ll t){
    ll flow=0;
    while(1){
        memset(used,0,sizeof(used));
        ll f=dfs(s,t,inf);
        if(f==0)return flow;
        flow+=f;
    }
}
///////////////////////////////////////
ll num(vector<ll>v,ll val){
    return lower_bound(v.begin(),v.end(),val)-v.begin();
}
struct plane{
    ll u,v,p,q,w;
};
int main(){
    ll n,m,d;cin>>n>>m>>d;
    vector<plane>pla;
    vector<ll>time[n];
    rep(i,0,m-1){
        plane aa;
        cin>>aa.u>>aa.v>>aa.p>>aa.q>>aa.w;aa.u--;aa.v--;
        aa.q+=d;
        time[aa.u].pb(aa.p);
        time[aa.v].pb(aa.q);
        pla.pb(aa);
    }
    rep(i,0,n-1){
        sort(time[i].begin(),time[i].end());
        time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
    }
    ll start[n+1];
    start[0]=0;
    rep(i,1,n){
        start[i]=start[i-1]+time[i-1].size();
    }
    rep(i,0,n-1){
        rep(j,0,time[i].size()-2){
            add_edge(start[i]+j,start[i]+j+1,inf);
        }
    }
    
    for(plane pp:pla){
        ll s=start[pp.u]+num(time[pp.u],pp.p);
        ll t=start[pp.v]+num(time[pp.v],pp.q);
        add_edge(s,t,pp.w);
    }
    
    cout<<max_flow(0,start[n]-1)<<endl;
    
    return 0;
}


0