結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー hirokazu1020hirokazu1020
提出日時 2016-12-18 00:22:44
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,770 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 103,168 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-05-08 04:20:41
合計ジャッジ時間 4,429 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 3 ms
5,888 KB
testcase_02 AC 2 ms
5,760 KB
testcase_03 AC 3 ms
5,760 KB
testcase_04 AC 3 ms
5,760 KB
testcase_05 AC 4 ms
5,888 KB
testcase_06 AC 3 ms
5,760 KB
testcase_07 AC 4 ms
5,760 KB
testcase_08 AC 4 ms
5,760 KB
testcase_09 AC 3 ms
5,760 KB
testcase_10 AC 3 ms
5,760 KB
testcase_11 AC 4 ms
5,760 KB
testcase_12 AC 3 ms
5,888 KB
testcase_13 AC 3 ms
5,888 KB
testcase_14 AC 5 ms
5,760 KB
testcase_15 AC 5 ms
5,760 KB
testcase_16 AC 4 ms
5,760 KB
testcase_17 AC 4 ms
5,760 KB
testcase_18 AC 5 ms
5,760 KB
testcase_19 AC 4 ms
5,888 KB
testcase_20 AC 5 ms
5,888 KB
testcase_21 AC 4 ms
5,760 KB
testcase_22 AC 5 ms
5,888 KB
testcase_23 AC 4 ms
5,760 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 4 ms
5,888 KB
testcase_36 AC 3 ms
5,760 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[50000];
vector<pair<int, int>> edge[50000];
 
int dp[50000];
bool critical[50000];

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