結果

問題 No.30 たこやき工場
ユーザー fiordfiord
提出日時 2015-07-18 07:17:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 753 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 153,412 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:15:36
合計ジャッジ時間 2,117 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> mpair;
typedef vector<mpair> pvec;
typedef long long int ll;
#define f first
#define s second
ll dp[101];
int main(){
	int n,m;	cin>>n>>m;
	vector<int> need(n+1,0);
	vector<pvec> lib(n+1);
	for(int i=0;i<m;i++){
		int p,q,r;	cin>>p>>q>>r;
		lib[r].push_back(make_pair(p,q));
		need[p]++;
	}
	dp[n]=1;
	queue<int> q;
	for(int i=1;i<=n;i++){
		if(need[i]==0)	q.push(i);
	}
	while(!q.empty()){
		int now=q.front();	q.pop();
		for(int i=0;i<(int)lib[now].size();i++){
			dp[lib[now][i].f]+=dp[now]*lib[now][i].s;
			need[lib[now][i].f]--;
			if(need[lib[now][i].f]==0)	q.push(lib[now][i].f);
		}
		if(lib[now].size()!=0)	dp[now]=0;
	}
	for(int i=1;i<n;i++)	cout<<dp[i]<<endl;
	return 0;
}
0