結果

問題 No.30 たこやき工場
ユーザー 0w10w1
提出日時 2016-12-13 13:30:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,457 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 174,988 KB
実行使用メモリ 8,056 KB
最終ジャッジ日時 2023-08-20 01:49:58
合計ジャッジ時間 8,628 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N;
int M;
vi P, Q, R;

void init(){
  cin >> N;
  cin >> M;
  P = Q = R = vi( M );
  for( int i = 0; i < M; ++i )
    cin >> P[ i ] >> Q[ i ] >> R[ i ],
    --P[ i ], --R[ i ];
}

vvp G;
vl ans;

void dfs( int u, int fa, ll v ){
  // cout << u << " " << fa << " " << v << endl;
  int transferred = 0;
  for( int i = 0; i < G[ u ].size(); ++i ){
    if( G[ u ][ i ].second == fa ) continue;
    transferred = 1;
    dfs( G[ u ][ i ].second, u, v * G[ u ][ i ].first );
  }
  if( not transferred )
    ans[ u ] = v;
}

void preprocess(){
  G = vvp( N );
  for( int i = 0; i < M; ++i )
    G[ R[ i ] ].emplace_back( Q[ i ], P[ i ] );
  ans = vl( N );
  dfs( N - 1, -1, 1LL );
}

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

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0