結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー antaanta
提出日時 2016-12-18 15:28:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 1,569 ms
コンパイル使用メモリ 173,116 KB
実行使用メモリ 11,968 KB
最終ジャッジ日時 2023-08-21 00:56:16
合計ジャッジ時間 4,681 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 124 ms
11,968 KB
testcase_25 AC 126 ms
11,768 KB
testcase_26 AC 123 ms
11,752 KB
testcase_27 AC 123 ms
11,808 KB
testcase_28 AC 122 ms
11,936 KB
testcase_29 AC 122 ms
11,696 KB
testcase_30 AC 125 ms
11,772 KB
testcase_31 AC 124 ms
11,748 KB
testcase_32 AC 125 ms
11,804 KB
testcase_33 AC 124 ms
11,808 KB
testcase_34 AC 38 ms
10,184 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N; int M;
	while (~scanf("%d%d", &N, &M)) {
		vector<vector<pair<int, int> > > gw(N);
		for (int i = 0; i < M; ++i) {
			int u, v, w;
			scanf("%d%d%d", &u, &v, &w);
			gw[u].push_back(make_pair(v, w));
		}
		vector<int> deg(N, 0);
		vector<int> ord(N, -1);
		vector<int> time(N, 0);
		rep(i, N) for (auto e : gw[i])
			++deg[e.first];
		int t = 0;
		ord[t++] = 0;
		for (int h = 0; h < t; h++) {
			int i = ord[h];
			for (auto e : gw[i]) {
				amax(time[e.first], time[i] + e.second);
				if (--deg[e.first] == 0)
					ord[t++] = e.first;
			}
		}
		assert(t == N);
		int num = 0;
		vector<int> latest(N, INF);
		latest[N - 1] = time[N - 1];
		for (int ix = N - 1; ix >= 0; --ix) {
			int i = ord[ix];
			for (auto e : gw[i])
				amin(latest[i], latest[e.first] - e.second);
			num += latest[i] != time[i];
		}
		printf("%d %d/%d\n", time[N - 1], num, N);
	}
	return 0;
}
0