結果

問題 No.30 たこやき工場
ユーザー omochana1omochana1
提出日時 2014-12-03 01:24:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,714 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 92,656 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:14:29
合計ジャッジ時間 1,502 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
#include <map>
#include <fstream>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <set>
#include <climits>
#define MAX_N 510
#define PI 3.141592653589
#define ESP 1e-20
#define BS 10
#define MOD 1000000007 
#define ZERO 10001
#define YJSNPI 810
#define INF (1LL << 50)
#define ADD(a, b) a = (a + (ll)b) % MOD
#define MUL(a, b) a = (a * (ll)b) % MOD
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

struct edge {
	int to, cost;
	edge(int to, int cost) : 
		to(to), cost(cost) {}
};

int N, M;
vector<edge> E[110];
vector<edge> rE[110];
int ans[110];
int dp[110];
bool used[110];
vector<int> vs;

void dfs(int v) {
	bool ok = false;
	used[v] = true;
	for(int i = 0; i < rE[v].size(); i++) {
		if(!used[rE[v][i].to]) dfs(rE[v][i].to); 
		ok = true;
	}
	if(!ok) vs.push_back(v);
}

int loop(int v) {
	if(v == N - 1) return 1;
	if(dp[v] != -1) return dp[v];
	int res = 0;
	for(int i = 0; i < E[v].size(); i++) {
		res += loop(E[v][i].to) * E[v][i].cost;
	}
	return dp[v] = res;
}

int main() {
	cin >> N >> M;
	for(int i = 0; i < M; i++) {
		int from, cost, to;
		cin >> from >> cost >> to;
		from--; to--;
		E[from].push_back(edge(to, cost));
		rE[to].push_back(edge(from, cost));
	}
	dfs(N - 1);
	memset(dp, -1, sizeof(dp));
	for(int i = 0; i < vs.size(); i++) {
		ans[vs[i]] = loop(vs[i]);
	}
	for(int i = 0; i < N - 1; i++) {
		printf("%d\n", ans[i]);
	}
}
0