結果

問題 No.654 Air E869120
ユーザー ayanamizutaayanamizuta
提出日時 2019-02-01 17:10:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,252 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 164,692 KB
実行使用メモリ 6,120 KB
最終ジャッジ日時 2023-08-14 15:30:21
合計ジャッジ時間 4,539 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,864 KB
testcase_01 AC 2 ms
5,920 KB
testcase_02 AC 3 ms
5,792 KB
testcase_03 AC 3 ms
5,972 KB
testcase_04 AC 2 ms
6,084 KB
testcase_05 AC 3 ms
5,812 KB
testcase_06 AC 2 ms
5,784 KB
testcase_07 AC 2 ms
6,072 KB
testcase_08 AC 2 ms
5,776 KB
testcase_09 AC 2 ms
6,104 KB
testcase_10 AC 6 ms
5,976 KB
testcase_11 AC 4 ms
6,064 KB
testcase_12 AC 5 ms
5,984 KB
testcase_13 AC 6 ms
5,980 KB
testcase_14 AC 6 ms
6,092 KB
testcase_15 AC 5 ms
6,052 KB
testcase_16 AC 4 ms
5,972 KB
testcase_17 AC 5 ms
6,036 KB
testcase_18 AC 5 ms
6,044 KB
testcase_19 AC 5 ms
6,120 KB
testcase_20 AC 4 ms
5,984 KB
testcase_21 AC 5 ms
5,964 KB
testcase_22 AC 4 ms
5,964 KB
testcase_23 AC 5 ms
6,116 KB
testcase_24 AC 4 ms
6,032 KB
testcase_25 AC 4 ms
6,096 KB
testcase_26 AC 4 ms
5,968 KB
testcase_27 AC 4 ms
5,948 KB
testcase_28 AC 4 ms
5,952 KB
testcase_29 AC 4 ms
5,944 KB
testcase_30 AC 4 ms
5,940 KB
testcase_31 AC 4 ms
5,900 KB
testcase_32 AC 3 ms
5,956 KB
testcase_33 AC 4 ms
5,888 KB
testcase_34 AC 4 ms
5,968 KB
testcase_35 AC 2 ms
5,920 KB
testcase_36 AC 2 ms
5,856 KB
testcase_37 AC 3 ms
5,856 KB
testcase_38 AC 2 ms
5,856 KB
testcase_39 AC 2 ms
5,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

class Flow {
public:
  struct edge {int to;long long cap;int rev;};
  static const int MAX_V=100000;
  static const long long  INF = 1e18;

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

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

  long long dfs(int v,int t,long long f){
    if(v==t) return f;
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
      edge &e = G[v][i];
      if(!used[e.to] && e.cap > 0){
	long long 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;
  }

  long long max_flow(int s,int t){
    long long flow = 0;
    while(true){
      memset(used,0,sizeof(used));
      long long f = dfs(s,t,INF);
      if(f == 0)return flow;
      flow+=f;
    }
  }
};

int n,m;
LL d;
int offset[1000];

int main(){
  cin>>n>>m>>d;
  Flow g;
  int u,v;
  LL p,q,w;
  vector<vector<tuple<int,int,LL,LL,LL> > > times(n);
  REP(i,m){
    cin>>u>>v>>p>>q>>w;u--;v--;
    times[u].push_back(make_tuple(u,v,p,q,w));
  }
  for_each(times.begin(),times.end(),[](vector<tuple<int,int,LL,LL,LL> > &v){sort(v.begin(),v.end(),[](const tuple<int,int,LL,LL,LL> x,const tuple<int,int,LL,LL,LL> y){return get<2>(x)<get<2>(y);});});
  offset[0]=0;
  REP(i,n-1){
    offset[i+1]=offset[i]+times[i].size();
  }
  REP(i,n-1){
    REP(j,times[i].size()){
      if(j!=times[i].size()-1){
	g.add(offset[i]+j,offset[i]+j+1,g.INF);
	if(get<2>(times[i][j])==get<2>(times[i][j+1]))g.add(offset[i]+j+1,offset[i]+j,g.INF);
      }
      int t = get<1>(times[i][j]);
      int arv = (int)(lower_bound(times[t].begin(),times[t].end(),make_tuple(0,0,d+get<3>(times[i][j]),0LL,0LL),[](const tuple<int,int,LL,LL,LL> x,const tuple<int,int,LL,LL,LL> y){return get<2>(x)<get<2>(y);})-times[t].begin());
      if((t==n-1) || (arv<times[t].size())){
	g.add(offset[i]+j,(t==n-1)?offset[t]:(offset[t]+arv),get<4>(times[i][j]));
      }
    }
  }
  cout<<g.max_flow(0,offset[n-1])<<endl;
  return 0;
}
0