結果

問題 No.30 たこやき工場
ユーザー omochana1omochana1
提出日時 2014-12-03 01:12:42
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,585 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 92,620 KB
実行使用メモリ 9,024 KB
最終ジャッジ日時 2023-09-02 01:20:42
合計ジャッジ時間 8,225 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];
vector<int> vs;

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

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

int main() {
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++) {
		int from, cost, to;
		scanf("%d%d%d", &from, &cost, &to);
		from--; to--;
		E[from].push_back(edge(to, cost));
		rE[to].push_back(edge(from, cost));
	}
	dfs(N - 1);
	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