結果

問題 No.30 たこやき工場
ユーザー togari_takamototogari_takamoto
提出日時 2016-02-26 00:45:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 170,584 KB
実行使用メモリ 7,752 KB
最終ジャッジ日時 2023-10-23 20:09:26
合計ジャッジ時間 9,409 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,368 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 4 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

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 mult) {
	if (g[id].empty()) return mult;

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

int main() {
	// cin.tie(0);
	// ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(5);
	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()) purchases_num[purchases_id[i]] = dfs(g, purchases_id[i], 1);
	REP(i, n - 1) cout << purchases_num[i] << endl;

	return 0;
}
0