結果

問題 No.30 たこやき工場
ユーザー anonyanony
提出日時 2014-09-26 00:02:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,246 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 85,124 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:13:35
合計ジャッジ時間 1,458 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// nm
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(long long i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

int n;
int d[101][101];
int dp[101];

int f(int a){
  if(a == n)return 1;
  if(dp[a]!=-1)return dp[a];
  int ret = 0;
  rep(i,0,101){
    if(d[a][i]!=-1){
      ret += f(i) * d[a][i];
    }
  }
  return dp[a] = ret;
}

int main(){
  clr(dp,-1);
  int m;
  cin >> n;
  cin >> m;
  clr(d,-1);
  rep(i,0,m){
    int p,q,r;
    cin >> p >> q >> r;
    d[p][r] = q;
  }
  
  rep(i,1,n){
    rep(j,0,101){
      if(d[j][i]!=-1){
        cout << 0 << endl;
        goto f;
      }
    }
    cout << f(i) << endl;
    f:;
  }
  
  return 0;
}

/*
#define MAX_V 50

vector<int> graph[MAX_V];
vector<int> rev_graph[MAX_V];
bool visited[MAX_V];
int cmp[MAX_V];
vector<int> st;

void dfs(int v){
  visited[v] = true;
  for(int i=0; i<(int)graph[v].size(); i++){
    int u = graph[v][i]; 
    if(!visited[u]){
    dfs(u);
    }
  }
  st.push_back(v);
}

void rev_dfs(int v, int cnt){
  visited[v] = true;
  for(int i=0; i<(int)rev_graph[v].size(); i++){
    int u = rev_graph[v][i];
    if(!visited[u]){
      rev_dfs(u, cnt);
    }
  }
  cmp[v] = cnt;
}

void scc(){
  memset(visited, 0, sizeof(visited));
  memset(cmp, 0, sizeof(cmp));
  st.clear();

  for(int i=0; i<MAX_V; i++){
    if(!visited[i]){
      dfs(i);
    }
  }

  memset(visited, 0, sizeof(visited));
  int cnt = 0;
  while(!st.empty()){
    int v = st.back();
    st.pop_back();
    if(!visited[v]){
      rev_dfs(v, cnt++);
    }
  }
}

int from[4] = {0,1,2,3};
int to[4] = {1,2,3,0};

int main(){
  rep(i,0,4){
    graph[from[i]].pb(to[i]);
    rev_graph[to[i]].pb(from[i]);
  }
  scc();
  rep(i,0,4){
    cout << cmp[i] << endl;
  }
    
  return 0;
}
*/
0