結果

問題 No.30 たこやき工場
ユーザー furonfuron
提出日時 2023-06-01 22:30:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,366 bytes
コンパイル時間 1,249 ms
コンパイル使用メモリ 130,420 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-08-28 02:11:02
合計ジャッジ時間 8,283 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,380 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 <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <random>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const int MOD = 998244353;

struct Edge {
	int to;
	ll cost;
};

using Graph = vector<vector<Edge>>;

void dfs(int s, Graph& g, ll cost, vl& ans) {
	if (g[s].size() == 0) {
		ans[s] += cost;
	}
	for (auto& v : g[s]) {
		dfs(v.to, g, cost * v.cost, ans);
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	vi p(m), q(m), r(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> q[i] >> r[i];
	}
	vl ans(n + 1, 0);
	Graph g(n + 1);
	for (int i = 0; i < m; i++) {
		g[r[i]].push_back({ p[i], q[i] });
	}

	dfs(n, g, 1, ans);
	
	for (int i = 1; i < n; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}
0