結果

問題 No.30 たこやき工場
ユーザー たこしたこし
提出日時 2014-11-13 21:17:06
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,483 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 90,604 KB
実行使用メモリ 7,840 KB
最終ジャッジ日時 2023-08-30 03:24:39
合計ジャッジ時間 7,746 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)

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

#define MAX_N 101
#define MAX_M 1501

int N, M;
int p[MAX_M], q[MAX_M], r[MAX_M];
vector<P> mate[MAX_N];//i番目の材料を作るのに必要な材料
                      //first:材料の原料の番号
                      //second:必要となる個数

int ans[MAX_N];//i番目の材料が何個必要か

vector<P> memo[MAX_N];
bool flag[MAX_N];
//DFS+メモ化で解く
//pos:現在見ている材料
void solve(int pos, int num){
  if(mate[pos].size() == 0){
    ans[pos] += num;
    return;
  }
  else{
    for(int i = 0; i < mate[pos].size(); i++){
      solve(mate[pos][i].first,num * mate[pos][i].second);
    }
  }
  return;
}

int main(){

  cin >> N >> M;
  for(int i = 0; i < M; i++){
    cin >> p[i] >> q[i] >>r[i];
    mate[r[i]].push_back(P(p[i], q[i]));   
  }

  solve(N, 1);//解く

  for(int i = 1; i <= N-1; i++){
    cout << ans[i] << endl;
  }

  return 0;
  
}
0