結果

問題 No.30 たこやき工場
ユーザー kenken714kenken714
提出日時 2020-04-08 02:15:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,272 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 99,584 KB
実行使用メモリ 8,456 KB
最終ジャッジ日時 2023-08-23 05:22:26
合計ジャッジ時間 1,742 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,932 KB
testcase_01 AC 5 ms
8,300 KB
testcase_02 AC 5 ms
8,120 KB
testcase_03 AC 6 ms
8,456 KB
testcase_04 AC 6 ms
8,388 KB
testcase_05 AC 6 ms
8,004 KB
testcase_06 AC 6 ms
8,448 KB
testcase_07 AC 6 ms
7,952 KB
testcase_08 AC 6 ms
8,376 KB
testcase_09 AC 6 ms
8,052 KB
testcase_10 AC 7 ms
8,392 KB
testcase_11 AC 6 ms
8,312 KB
testcase_12 AC 6 ms
8,120 KB
testcase_13 AC 5 ms
8,448 KB
testcase_14 AC 6 ms
8,304 KB
testcase_15 AC 6 ms
7,948 KB
testcase_16 AC 6 ms
7,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

vector<P> g[110000];
vector<ll> ans(110000), in(110000);
int main() {
	ll n, m;
	cin >> n >> m;
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		c--;
		g[c].push_back(P(a, b));
		in[a]++;
	}
	queue<ll> que;
	REP(i, n) if (in[i] == 0)que.push(i);
	ans[n - 1] = 1;
	while (!que.empty()) {
		ll now = que.front();
		ans.push_back(now);
		que.pop();
		REP(i, g[now].size()) {
			ll v = g[now][i].first;
			in[v]--;
			ans[v] += ans[now] * g[now][i].second;
			if (in[v] == 0) que.push(v);
		}
		if (g[now].size())ans[now] = 0;
	}
	REP(i, n - 1)cout << ans[i] << endl;
}
0