結果

問題 No.298 話の伝達
ユーザー Kmcode1Kmcode1
提出日時 2015-11-07 00:17:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,085 bytes
コンパイル時間 2,854 ms
コンパイル使用メモリ 105,136 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-11 14:37:08
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define __float128 double
#define MAX 22
__float128 dp[MAX];
vector<pair<int,__float128> > v[MAX];
int deg[MAX];
vector<pair<int,__float128> > pp[MAX];
int n;
int m;
queue<int> q;
struct st {
	int a, b;
	double p;
	st() {
		scanf("%d%d", &a, &b);
		scanf("%lf", &p);
		p /= 100.0;
	}
};
vector<st> vv;
bool use[MAX];
inline void dfs(int b) {
	deg[b]--;
	if (deg[b] < 0 && b != 0) {
		exit(1);
	}
	if (deg[b] <= 0) {
		const int k = 1 << (pp[b].size());
		for (int i = 1;i < k;i++) {
			__float128 sum = 1.0;
			bool flag = false;
			for (int j = 0;j < pp[b].size();j++) {
				if ((i >> j) & 1) {
					sum *= dp[pp[b][j].first] *(__float128)( pp[b][j].second);
					flag ^= true;
				}
			}
			if (flag) {
				dp[b] += sum;
			}
			else {
				dp[b] -= sum;
			}
		}
		for (int i = 0;i < v[b].size();i++) {
			dfs(v[b][i].first);
		}
	}
}
int main() {
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		vv.push_back(st());
		v[vv.back().a].push_back(make_pair(vv.back().b, vv.back().p));
	}
	memset(use, true, sizeof(use));
	use[0] = true;
	q.push(0);
	while (!q.empty()) {
		int b = q.front();
		q.pop();
		for (int i = 0;i < v[b].size();i++) {
			if (use[v[b][i].first]) {
				continue;
			}
			q.push(v[b][i].first);
			use[v[b][i].first] = true;
		}
	}
	for (int i = 0;i < n;i++) {
		v[i].clear();
	}
	for (int i = 0;i < m;i++) {
		if (use[vv[i].a] && use[vv[i].b]) {
			v[vv[i].a].push_back(make_pair(vv[i].b, vv[i].p));
			deg[vv[i].b]++;
			pp[vv[i].b].push_back(make_pair(vv[i].a,vv[i].p));
		}
	}
	dp[0] = 1.0;
	dfs(0);
	double ans = dp[n - 1];
	printf("%.16f\n", ans);
	return 0;
}
0