結果

問題 No.654 Air E869120
ユーザー hana314hana314
提出日時 2018-09-18 14:02:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 788 ms / 2,000 ms
コード長 2,163 bytes
コンパイル時間 1,772 ms
コンパイル使用メモリ 73,128 KB
実行使用メモリ 58,668 KB
最終ジャッジ日時 2023-09-25 09:47:59
合計ジャッジ時間 5,692 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
52,552 KB
testcase_01 AC 25 ms
54,044 KB
testcase_02 AC 21 ms
52,464 KB
testcase_03 AC 20 ms
54,000 KB
testcase_04 AC 21 ms
52,412 KB
testcase_05 AC 20 ms
53,952 KB
testcase_06 AC 20 ms
52,344 KB
testcase_07 AC 21 ms
54,252 KB
testcase_08 AC 21 ms
52,460 KB
testcase_09 AC 20 ms
54,100 KB
testcase_10 AC 788 ms
54,088 KB
testcase_11 AC 274 ms
53,360 KB
testcase_12 AC 457 ms
55,184 KB
testcase_13 AC 507 ms
53,460 KB
testcase_14 AC 185 ms
55,096 KB
testcase_15 AC 216 ms
53,804 KB
testcase_16 AC 47 ms
53,160 KB
testcase_17 AC 58 ms
54,620 KB
testcase_18 AC 41 ms
52,952 KB
testcase_19 AC 62 ms
54,524 KB
testcase_20 AC 27 ms
52,860 KB
testcase_21 AC 25 ms
54,576 KB
testcase_22 AC 23 ms
52,924 KB
testcase_23 AC 25 ms
54,436 KB
testcase_24 AC 26 ms
52,816 KB
testcase_25 AC 23 ms
54,644 KB
testcase_26 AC 24 ms
52,896 KB
testcase_27 AC 23 ms
54,472 KB
testcase_28 AC 25 ms
52,944 KB
testcase_29 AC 23 ms
54,624 KB
testcase_30 AC 26 ms
57,408 KB
testcase_31 AC 26 ms
58,656 KB
testcase_32 AC 25 ms
57,316 KB
testcase_33 AC 25 ms
58,668 KB
testcase_34 AC 25 ms
57,460 KB
testcase_35 AC 21 ms
54,000 KB
testcase_36 AC 20 ms
52,392 KB
testcase_37 AC 20 ms
53,968 KB
testcase_38 AC 21 ms
52,384 KB
testcase_39 AC 20 ms
54,096 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) {
	LL 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