結果

問題 No.30 たこやき工場
ユーザー kyuridenamida
提出日時 2016-02-11 08:56:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 163,980 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-21 05:23:28
合計ジャッジ時間 2,303 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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