結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー furafura
提出日時 2020-08-07 01:39:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 2,314 ms
コンパイル使用メモリ 215,136 KB
実行使用メモリ 11,496 KB
最終ジャッジ日時 2023-10-22 05:00:59
合計ジャッジ時間 6,505 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 126 ms
11,484 KB
testcase_25 AC 125 ms
11,492 KB
testcase_26 AC 126 ms
11,496 KB
testcase_27 AC 128 ms
11,496 KB
testcase_28 AC 126 ms
11,484 KB
testcase_29 AC 125 ms
11,496 KB
testcase_30 AC 125 ms
11,492 KB
testcase_31 AC 127 ms
11,484 KB
testcase_32 AC 122 ms
11,480 KB
testcase_33 AC 123 ms
11,480 KB
testcase_34 AC 38 ms
9,888 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

using namespace std;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_directed_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
}

template<class T>
vector<int> topological_order(const weighted_graph<T>& D){
	int n=D.size();
	vector<int> deg(n);
	rep(u,n) for(const auto& e:D[u]) deg[e.to]++;

	vector<int> res;
	queue<int> Q;
	rep(u,n) if(deg[u]==0) Q.emplace(u);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		res.emplace_back(u);
		for(const auto& e:D[u]) if(--deg[e.to]==0) Q.emplace(e.to);
	}
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	weighted_graph<int> G(n);
	rep(i,m){
		int u,v,c; scanf("%d%d%d",&u,&v,&c);
		add_directed_edge(G,u,v,c);
	}

	auto p=topological_order(G);

	vector<int> dp(n);
	for(int u:p){
		for(auto e:G[u]) dp[e.to]=max(dp[e.to],dp[u]+e.wt);
	}

	vector<bool> ok(n);
	ok[n-1]=true;
	rep(i,n){
		int u=p[n-1-i];
		for(auto e:G[u]) if(ok[e.to] && dp[e.to]==dp[u]+e.wt) ok[u]=true;
	}
	printf("%d %ld/%d\n",dp[n-1],count(ok.begin(),ok.end(),false),n);

	return 0;
}
0