結果

問題 No.298 話の伝達
コンテスト
ユーザー mayoko_
提出日時 2015-11-07 00:43:49
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,560 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 934 ms
コンパイル使用メモリ 109,828 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-04 05:29:02
合計ジャッジ時間 6,158 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXM = 30;
int A[MAXM], B[MAXM], C[MAXM];
bool vis[MAXM];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    if (M > 30) return 0;
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
    }
    double ans = 0;
    for (int s = 0; s < 1<<M; s++) {
        double tmp = 1;
        for (int i = 0; i < M; i++) {
            if ((s>>i)&1) tmp *= C[i]/100.;
            else tmp *= 1-C[i]/100.;
        }
        queue<int> que;
        memset(vis, false, sizeof(vis));
        que.push(0);
        while (!que.empty()) {
            int now = que.front();
            vis[now] = true;
            que.pop();
            for (int i = 0; i < M; i++) {
                if (now == A[i] && ((s>>i)&1)) if (!vis[B[i]]) {
                    que.push(B[i]);
                    vis[B[i]] = true;
                }
            }
        }
        if (vis[N-1]) ans += tmp;
    }
    printf("%.10lf\n", ans);
    return 0;
}
0