結果

問題 No.30 たこやき工場
ユーザー antaanta
提出日時 2014-09-25 23:47:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 845 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 70,088 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:13:36
合計ジャッジ時間 1,432 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 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,376 KB
testcase_13 AC 1 ms
4,380 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
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
 
vector<vector<int> > g, gw;
vector<long long> memo;
 
long long rec(int i) {
	long long &r = memo[i];
	if(r != -1) return r;
	if(i == (int)g.size() - 1)
		return r = 1;
	r = 0;
	for(int j = 0; j < (int)g[i].size(); ++ j)
		r += rec(g[i][j]) * gw[i][j];
	return r;
}
 
int main() {
	int N, M;
	while(~scanf("%d%d", &N, &M)) {
		g.assign(N, vector<int>());
		gw.assign(N, vector<int>());
		vector<bool> producable(N, false);
		for(int i = 0; i < M; ++ i) {
			int P, Q, R;
			scanf("%d%d%d", &P, &Q, &R), -- P, -- R;
			g[P].push_back(R);
			gw[P].push_back(Q);
			producable[R] = true;
		}
		memo.assign(N, -1);
		for(int i = 0; i < N-1; ++ i)
			printf("%lld\n", producable[i] ? 0 : rec(i));
	}
	return 0;
}
0