結果

問題 No.654 Air E869120
ユーザー hana314hana314
提出日時 2018-09-18 11:20:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,164 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 73,884 KB
実行使用メモリ 58,912 KB
最終ジャッジ日時 2023-09-25 09:43:50
合計ジャッジ時間 5,336 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
53,984 KB
testcase_01 AC 20 ms
54,176 KB
testcase_02 AC 20 ms
54,000 KB
testcase_03 AC 20 ms
53,984 KB
testcase_04 AC 20 ms
53,988 KB
testcase_05 AC 21 ms
54,176 KB
testcase_06 AC 21 ms
54,000 KB
testcase_07 AC 21 ms
53,948 KB
testcase_08 AC 21 ms
53,988 KB
testcase_09 AC 21 ms
54,172 KB
testcase_10 AC 795 ms
55,616 KB
testcase_11 AC 274 ms
55,168 KB
testcase_12 AC 462 ms
55,324 KB
testcase_13 AC 496 ms
55,224 KB
testcase_14 AC 187 ms
55,064 KB
testcase_15 AC 219 ms
55,300 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 23 ms
54,468 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 23 ms
54,332 KB
testcase_26 WA -
testcase_27 AC 23 ms
54,476 KB
testcase_28 WA -
testcase_29 AC 23 ms
54,408 KB
testcase_30 AC 26 ms
58,740 KB
testcase_31 AC 26 ms
58,652 KB
testcase_32 AC 26 ms
58,596 KB
testcase_33 AC 25 ms
58,792 KB
testcase_34 AC 25 ms
58,912 KB
testcase_35 AC 21 ms
54,152 KB
testcase_36 AC 21 ms
53,984 KB
testcase_37 AC 21 ms
54,224 KB
testcase_38 AC 20 ms
53,968 KB
testcase_39 AC 21 ms
54,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<iostream>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;
#include<vector>
using namespace std;
const int MAX_V = 1001;
const int INF = 2000000000;
struct edge {
	int to;//行先
	int capacity;//容量
	int reverse;//逆辺
};

vector<edge> G[MAX_V*2000];
bool used[MAX_V*2000];

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

LL dfs(int v, int t, LL 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.capacity > 0) {//使える辺を見つけたら
			LL d = dfs(e.to, t, min(f, (LL)e.capacity));
			if (d>0) {
				e.capacity -= d;
				G[e.to][e.reverse].capacity += d;
				return d;
			}
		}
	}
	return 0;
}

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

#define _CRT_SECURE_NO_WARNINGS

int N,M,d = 0;
int u[MAX_V], v[MAX_V], p[MAX_V], q[MAX_V], w[MAX_V];

const int MAX_DEG = 1001;
int outdeg[MAX_V] = {};
int startTime[MAX_V][MAX_DEG];

int indeg[MAX_V] = {};
int goalTime[MAX_V][MAX_DEG];

int main() {
	cin >> N >> M >> d;
	for (int i = 0; i < M;i++) {
		cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i];
		AddEdge(u[i] * 2000 + 1000+outdeg[u[i]], v[i] * 2000 + indeg[v[i]], w[i]);
		startTime[ u[i] ][ outdeg[u[i]] ] = p[i];
		goalTime[v[i]][indeg[v[i]]] = q[i];
		outdeg[u[i]]++;
		indeg[v[i]]++;
	}
	for (int i = 1; i <= N;i++) {
		for (int j = 0; j < indeg[i];j++) {
			for (int k = 0; k < outdeg[i];k++) {
				if ( goalTime[i][j]+d <= startTime[i][k] ) {
					AddEdge(i * 2000 + j, i * 2000+1000 + k, INF);
				}
			}
		}
	}
	for (int i = 0; i < outdeg[1];i++) {
		AddEdge(0, 2000 +1000+ i, INF);
			}
	for (int i = 0; i < indeg[N];i++) {
		AddEdge(N * 2000 + i, 1, INF);
	}
	cout << max_flow(0, 1) << endl;
	return 0;
}
0