結果

問題 No.30 たこやき工場
ユーザー Yang33Yang33
提出日時 2018-04-09 20:00:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,907 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 170,932 KB
実行使用メモリ 7,524 KB
最終ジャッジ日時 2023-09-09 03:35:24
合計ジャッジ時間 8,630 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 2 ms
4,376 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 VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/04/09  Problem: yukicoder 030  / Link: http://yukicoder.me/problems/no/030  ----- */
/* ------問題------

太郎君はとある工場を建てようとしています。
効率よく生産するためには、材料を計画的に購入しなければなりません。
この工場では、最終的に製造したい製品を 製品番号N とし、
製品番号1 ~ N−1 の中間素材となる製品を取り扱います。

製品番号1 ~ N−1 の製品は、外部から購入するか、
またはこの工場で製造するかのどちらかにより手に入るものとします。
また、最終製品Nも含め製造することが出来る製品は、外部から購入せずに必ず製造するものとします。

入力に、各製品番号(1~N)の製造方法(材料の製品番号・個数と、その材料から1個製造できる製品番号)
が与えられるので、最終製品Nを1個作るために、外部から購入する必要のある最小の個数を
1~N−1番の 製品番号ごとにそれぞれ1行で出力してください。

製品iの製造方法が複数書かれている場合は、それらすべての材料が必要です。
製品Nを製造するための製造方法は必ず与えられます。

-----問題ここまで----- */
/* -----解説等-----

rG dag

----解説ここまで---- */

LL N, M;

LL ans = 0LL;

void dfs(int n, int c, VL& need, vector<vector<PII>>& G) {
	if (SZ(G[n]) == 0) {
		need[n] += c;
	}
	else {
		FOR(i, 0, SZ(G[n])) {
			int nv = G[n][i].first; int cost = G[n][i].second;
			dfs(nv, c*cost, need, G);
		}
	}
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N >> M;
	vector<vector<PII>> rG(N);
	FOR(i, 0, M) {
		int a, b, c; cin >> a >> b >> c;
		a--; c--;
		rG[c].push_back(PII(a, b));
	}
	
	vector<LL> need(N, 0);
	dfs(N - 1, 1, need, rG);
	FOR(i, 0, N - 1) {
		cout << need[i] << endl;
	}


	return 0;
}
0