結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー hirokazu1020hirokazu1020
提出日時 2016-12-18 00:23:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,774 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 99,708 KB
実行使用メモリ 17,068 KB
最終ジャッジ日時 2023-08-20 22:08:42
合計ジャッジ時間 4,315 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,200 KB
testcase_01 AC 4 ms
8,184 KB
testcase_02 AC 4 ms
8,056 KB
testcase_03 AC 4 ms
8,260 KB
testcase_04 AC 4 ms
8,064 KB
testcase_05 AC 5 ms
8,132 KB
testcase_06 AC 5 ms
8,280 KB
testcase_07 AC 4 ms
8,092 KB
testcase_08 AC 5 ms
8,092 KB
testcase_09 AC 4 ms
8,072 KB
testcase_10 AC 4 ms
8,208 KB
testcase_11 AC 4 ms
8,064 KB
testcase_12 AC 4 ms
8,072 KB
testcase_13 AC 5 ms
8,040 KB
testcase_14 AC 5 ms
8,348 KB
testcase_15 AC 6 ms
8,152 KB
testcase_16 AC 6 ms
8,164 KB
testcase_17 AC 5 ms
8,156 KB
testcase_18 AC 6 ms
8,188 KB
testcase_19 AC 5 ms
8,180 KB
testcase_20 AC 5 ms
8,300 KB
testcase_21 AC 6 ms
8,176 KB
testcase_22 AC 5 ms
8,212 KB
testcase_23 AC 6 ms
8,364 KB
testcase_24 AC 150 ms
17,040 KB
testcase_25 AC 151 ms
17,056 KB
testcase_26 AC 151 ms
17,068 KB
testcase_27 AC 151 ms
16,944 KB
testcase_28 AC 150 ms
17,036 KB
testcase_29 AC 151 ms
16,896 KB
testcase_30 AC 151 ms
16,916 KB
testcase_31 AC 150 ms
16,988 KB
testcase_32 AC 148 ms
16,976 KB
testcase_33 AC 148 ms
16,892 KB
testcase_34 AC 46 ms
15,108 KB
testcase_35 AC 4 ms
8,164 KB
testcase_36 AC 5 ms
8,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



vector<int> topologicalSort(int v, const vector<int> edge[]) {
	vector<int> zeros;
	vector<int> in(v), res;
	for (int i = 0; i<v; i++) {
		for (int j = 0; j<(int)edge[i].size(); j++)in[edge[i][j]]++;
	}
	for (int i = 0; i<v; i++)if (in[i] == 0)zeros.push_back(i);
	while (!zeros.empty()) {
		int u = zeros.back();
		zeros.pop_back();
		res.push_back(u);
		for (int i = 0; i<(int)edge[u].size(); i++) {
			if (--in[edge[u][i]] == 0)zeros.push_back(edge[u][i]);
		}
	}
	return res;
}





int n, m;
vector<int> e[100000];
vector<pair<int, int>> edge[100000];
 
int dp[100000];
bool critical[100000];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	rep(i,m) {
		int a, b, c;
		cin >> a >> b >> c;
		e[a].push_back(b);
		edge[a].emplace_back(b, c);
	}
	auto ord = topologicalSort(n, e);
	rep(i,n) {
		for (auto p : edge[ord[i]]) {
			dp[p.first] = max(dp[p.first], dp[ord[i]] + p.second);
		}
	}
	critical[n - 1] = true;
	int cnt = 0;
	for (int i = n - 2; i >= 0;i--){
		bool f = true;
		for (auto p : edge[ord[i]]) {
			if (critical[p.first] && dp[p.first] == dp[ord[i]] + p.second)f = false;
		}
		if (f)cnt++;
		else critical[ord[i]] = true;
	}

	cout << dp[n - 1] << ' ' << cnt << '/' << n << endl;

	
	return 0;
}
0