結果

問題 No.654 Air E869120
ユーザー IKyoproIKyopro
提出日時 2019-06-12 23:51:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 2,077 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 77,564 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 06:22:36
合計ジャッジ時間 2,274 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll;
ll inf = 1e18;
struct edge{ll to, cap, rev;};
vector<edge> G[10010];
int level[10010];
int iter[10010];
void add_edge(ll from, ll to, ll cap){
	G[from].push_back((edge){to,cap,(int) G[to].size()});
	G[to].push_back((edge){from,0,(int) G[from].size()-1});
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> Q;
	level[s] = 0;
	Q.push(s);
	while(!Q.empty()){
		int v = Q.front(); Q.pop();
		for(int 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;
				Q.push(e.to);
			}
		}
	}
}

ll dfs(int v,int t,ll f){
	if(v==t) return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e = G[v][i];
		if(level[v]<level[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;
	for(;;){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter,0,sizeof(iter));
		ll f;
		while((f=dfs(s,t,inf))>0) flow += f;
	}
}

struct e{
    ll to,p,q,w,id;
    bool operator<(const e& right)const{
        return p<right.p;
    }
};

vector<vector<e>> v(1010);
int N,M,D;

int main(){
    cin >> N >> M >> D;
    ll a,b,p,q,w;
    for(int i=1;i<=M;i++){
        cin >> a >> b >> p >> q >> w;
        v[a].push_back({b,p,q,w,i});
    }
    for(int i=1;i<=N;i++) sort(v[i].begin(),v[i].end());
    for(int i=1;i<=N;i++){
        for(int j=0;j<v[i].size();j++){
            if(i==1) add_edge(0,v[i][j].id,inf);
            if(j!=v[i].size()-1) add_edge(v[i][j].id,v[i][j+1].id,inf);
            int to = v[i][j].to;
            if(to==N) add_edge(v[i][j].id,M+1,v[i][j].w);
            else{
                for(auto x:v[to]){
                    if(v[i][j].q+D<=x.p){
                        add_edge(v[i][j].id,x.id,v[i][j].w);
                        break;
                    }
                }
            }
        }
    }
    cout << max_flow(0,M+1);
}
0