結果

問題 No.30 たこやき工場
ユーザー togari_takamototogari_takamoto
提出日時 2016-02-26 01:02:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,106 bytes
コンパイル時間 1,384 ms
コンパイル使用メモリ 154,724 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 05:16:59
合計ジャッジ時間 2,185 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi  = vector<int>; using vb  = vector<bool>; using vd  = vector<double>; using vl  = vector<ll>;
using vvi = vector<vi>;  using vvb = vector<vb>;   using vvd = vector<vd>;     using vvl = vector<vl>;

#define REP(i,n) for(ll i=0; i<(n); ++i)

ll dfs(const vector<vector<pair<ll, ll>>> & g, ll id, ll goal, vl & store) {
	if (store[id] != -1) return store[id];
	if (id == goal) return 1;
	if (g[id].empty()) return 0;

	ll num = 0;
	for (auto&& e : g[id]) num += e.second * dfs(g, e.first, goal, store);
	return store[id] = num;
}

int main() {
	ll n,m;
	cin >> n >> m;
	vector<vector<pair<ll,ll>>> g(n);
	vb purchases_b(n, true);
	REP(i, m) {
		ll p, q, r;
		cin >> p >> q >> r;
		g[p-1].push_back({ r-1, q });
		purchases_b[r-1] = false;
	}

	vl purchases_id; REP(i, n) if (purchases_b[i]) purchases_id.push_back(i);
	vl purchases_num(n, 0);
	REP(i, purchases_id.size()) {
		vl store(n, -1);
		purchases_num[purchases_id[i]] = dfs(g, purchases_id[i], n - 1, store);
	}
	REP(i, n - 1) cout << purchases_num[i] << endl;

	return 0;
}
0