結果

問題 No.30 たこやき工場
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-11 08:56:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 150,112 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:17:07
合計ジャッジ時間 2,233 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++)
#define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++)
#define all(n) (n).begin(),(n).end()
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int,int> Pii;
typedef vector<Pii> VPii;


long long dp[110];
vector<Pii> g[110];
vector<int> rev[110];
int dn[110];

int main(){
	int N,M;
	cin >> N >> M;
	rep(i,M){
		int a,b,c;
		cin >> a >> b >> c;
		--a,--c;
		rev[a].push_back(c);
		g[c].push_back({a,b});
	}
	dp[N-1] = 1;
	while(true){
		int ref = 0;
		rep(i,N){
			if( dn[i] ) continue;
			int ok = 1;
			for( auto j : rev[i] )
				if( !dn[j] ) ok = 0;
			if(ok){
				ref = 1;
				for( auto j : g[i] ){
					dp[j.first] += (long long)j.second * dp[i];
				}
				dn[i] = 1;
			}
		}
		if(!ref) break;
	}
	for(int i = 0 ; i < N-1 ; i++)
		cout << (g[i].size()?0:dp[i]) << endl;
	
}
0