結果

問題 No.654 Air E869120
ユーザー chocoruskchocorusk
提出日時 2019-05-20 23:36:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,510 bytes
コンパイル時間 1,111 ms
コンパイル使用メモリ 115,140 KB
実行使用メモリ 15,844 KB
最終ジャッジ日時 2023-10-17 08:12:03
合計ジャッジ時間 3,645 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 6 ms
5,100 KB
testcase_16 AC 64 ms
15,844 KB
testcase_17 AC 63 ms
15,784 KB
testcase_18 AC 62 ms
15,612 KB
testcase_19 AC 63 ms
15,844 KB
testcase_20 AC 54 ms
9,944 KB
testcase_21 AC 54 ms
9,844 KB
testcase_22 AC 53 ms
10,052 KB
testcase_23 AC 53 ms
9,932 KB
testcase_24 AC 53 ms
9,952 KB
testcase_25 AC 49 ms
8,924 KB
testcase_26 AC 52 ms
9,660 KB
testcase_27 AC 47 ms
7,148 KB
testcase_28 AC 49 ms
7,084 KB
testcase_29 AC 47 ms
6,948 KB
testcase_30 AC 43 ms
4,348 KB
testcase_31 AC 43 ms
4,348 KB
testcase_32 AC 43 ms
4,348 KB
testcase_33 AC 44 ms
4,348 KB
testcase_34 AC 43 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e16;
struct edge {int to; long long int cap; int rev;} ;
 
vector<edge> G[2010];
int level[2010];
int iter[2010];
 
void add_edge(int from, int to, long long int cap){
	edge e;
	e.to=to, e.cap=cap, e.rev=G[to].size();
	G[from].push_back(e);
	e.to=from, e.cap=0, e.rev=G[from].size()-1;
	G[to].push_back(e);
}
 
void bfs(int s){
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.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;
				que.push(e.to);
			}
		}
	}
}
 
long long int dfs(int v, int t, long long int f){
	if(v==t) return f;
	for(int &i=iter[v]; i<G[v].size(); i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			long long int 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 int max_flow(int s, int t){
	long long int flow=0;
	while(1){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter, 0, sizeof(iter));
		long long int f;
		while((f=dfs(s, t, INF))>0){
			flow+=f;
		}
	}
}

int main()
{
    int n, m, d; cin>>n>>m>>d;
    map<P, int> mp;
    int c=0;
    for(int i=0; i<m; i++){
        int u, v, p, q; ll w;
        cin>>u>>v>>p>>q>>w;
        if(mp.find({u, p})==mp.end()){
            mp[{u, p}]=c; c++;
        }
        if(mp.find({v, q})==mp.end()){
            mp[{v, q}]=c; c++;
        }
        add_edge(mp[{u, p}], mp[{v, q}], w);
    }
    for(auto p:mp){
        for(auto q:mp){
            int u=p.first.first, v=q.first.first;
            if(u!=v) continue;
            int x=p.first.second, y=q.first.second;
            if(x+d<=y){
                add_edge(p.second, q.second, INF);
            }
        }
    }
    int s=c, t=c+1;
    for(auto p:mp){
        if(p.first.first==1){
            add_edge(s, p.second, INF);
        }else if(p.first.first==n){
            add_edge(p.second, t, INF);
        }
    }
    cout<<max_flow(s, t)<<endl;
    return 0;
}
0