結果

問題 No.654 Air E869120
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2018-06-11 11:52:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 1,705 bytes
コンパイル時間 1,185 ms
コンパイル使用メモリ 151,176 KB
実行使用メモリ 6,628 KB
最終ジャッジ日時 2023-09-13 02:55:05
合計ジャッジ時間 3,790 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 390 ms
6,628 KB
testcase_11 AC 113 ms
5,680 KB
testcase_12 AC 195 ms
5,820 KB
testcase_13 AC 218 ms
6,064 KB
testcase_14 AC 71 ms
5,536 KB
testcase_15 AC 95 ms
6,496 KB
testcase_16 AC 13 ms
4,604 KB
testcase_17 AC 15 ms
4,640 KB
testcase_18 AC 12 ms
4,812 KB
testcase_19 AC 16 ms
4,620 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:55:8: warning: first argument of ‘int main(long long int, const char**)’ should be ‘int’ [-Wmain]
 signed main(int argc, char const *argv[])
        ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

#define int long long

#define INF 1e15

const int MAX_V = 2010; //必要な頂点数
struct Flow{
	struct edge{
		int to, cap, rev;
	};
	vector<edge> G[MAX_V];//隣接リスト
	bool used[MAX_V];
 
	void add_edge(int from, int to, int cap){
		G[from].push_back((edge){to, cap, (int)G[to].size()});//from -> to
		G[to].push_back((edge){from, 0, (int)G[from].size() - 1});//to -> from
	}
	//増加パスを探す
	int dfs(int v, int t, int 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){
				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;
	}
	//sからtへの最大流
	int max_flow(int s, int t){
		int flow = 0;
		while(1){
			memset(used, 0, sizeof(used));
			int f = dfs(s, t, INF);
			if(f == 0) return flow;
			flow += f;
		}
	}
};



signed main(int argc, char const *argv[])
{
	int n, m, d; cin >> n >> m >> d;
	vector<int> u(m), v(m), p(m), q(m), w(m);
	rep(i, m) cin >> u[i] >> v[i] >> p[i] >> q[i] >> w[i];
	rep(i, m) u[i]--, v[i]--;
	int start = 2 * m, goal = 2 * m + 1;


	Flow fw;

	rep(i, m) {
		fw.add_edge(i, i + m, w[i]);
	}

	rep(i, m)rep(j, m) {
		if (i == j) continue;
		if (v[i] == u[j] && q[i] + d <= p[j]){
			fw.add_edge(i + m, j, INF + 1);
		}
	}

	// start
	rep(i, m) if(u[i] == 0) fw.add_edge(start, i, INF + 1);
	rep(i, m) if(v[i] == n - 1) fw.add_edge(i + m, goal, INF + 1);


	printf("%lld\n", fw.max_flow(start, goal));
	return 0;
}
0