結果

問題 No.30 たこやき工場
ユーザー masamasa
提出日時 2015-01-31 23:12:00
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,086 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 83,436 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 08:39:20
合計ジャッジ時間 1,999 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>

using namespace std;

int main() {
	int n, m;

	cin >> n >> m;
	vector< vector< pair<int, int>  > > recipe(n + 1, vector< pair<int, int> >());
	vector< set<int> > materials(n + 1, set<int>());
	int p, q, r;
	for (int i = 0; i < m; i++) {
		cin >> p >> q >> r;
		recipe[r].push_back(make_pair(p, q));
		materials[p].insert(r);
	}

	vector<long long> need(n + 1, 0);
	vector<bool> check(n + 1, 0);

	need[n] = 1;
	check[0] = true;
	bool update = true;
	while (update) {
		update = false;
		for (int i = 1; i <= n; i++) {
			if (need[i] > 0 && !check[i] && materials[i].size() == 0) {

				update = true;
				for (int j = 0; j < recipe[i].size(); j++) {
					pair<int, int> tmp = recipe[i][j];
					need[tmp.first] += need[i] * tmp.second;
				}
				if (!recipe[i].empty()) {
					need[i] = 0;
				}
				check[i] = true;
				for (int k = 1; k <= n; k++) {
					materials[k].erase(i);
				}
			}
		}
	}

	for (int i = 1; i < n; i++) {
		cout << need[i] << endl;
	}
	return 0;
}
0