結果

問題 No.30 たこやき工場
ユーザー snrnsidy
提出日時 2021-05-10 03:24:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 851 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 201,112 KB
最終ジャッジ日時 2025-01-21 09:42:54
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int n, m, p, q, r;
vector <pair<int,int>> adj[101];
int indegree[101];
int indegree2[101];
long long int dist[101];
int arr[101];
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> p >> q >> r;
		adj[r].push_back(make_pair(p, q));
		indegree[p]++;
		indegree2[r]++;
	}

	queue <int> que;
	dist[n] = 1;
	que.push(n);

	while (!que.empty())
	{
		int now = que.front();
		que.pop();
		for (auto it : adj[now])
		{
			int next = it.first;
			int cost = it.second;
			dist[next] += (cost * dist[now]);
			indegree[next]--;
			if (indegree[next] == 0)
			{
				que.push(next);
			}
		}
	}

	for (int i = 1; i < n; i++)
	{
		if (indegree2[i] == 0)
		{
			cout << dist[i] << '\n';
		}
		else
		{
			cout << 0 << '\n';
		}
	}
	return 0;
}
0