結果

問題 No.298 話の伝達
ユーザー koba-e964koba-e964
提出日時 2017-01-25 21:14:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,165 bytes
コンパイル時間 2,753 ms
コンパイル使用メモリ 89,512 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 23:12:22
合計ジャッジ時間 2,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

typedef pair<double, int> PDI;
const int N = 30;

vector<PDI> edges[N];
double dp[N];

double rec(int v) {
  if (dp[v] >= 0) {
    return dp[v];
  }
  if (v == 0) {
    return 1;
  }
  double prod = 1.0;
  for (auto &w: edges[v]) {
    prod *= 1 - rec(w.second) * w.first;
  }
  return dp[v] = 1 - prod;
}

int main(void){
  int n, m;
  cin >> n >> m;
  REP(i, 0, m) {
    int a, b;
    double c;
    cin >> a >> b >> c;
    c /= 100;
    edges[b].push_back(PDI(c, a));
  }
  REP(i, 0, n) {
    dp[i] = -1;
  }
  printf("%.15f\n", rec(n - 1));
}
0