結果

問題 No.298 話の伝達
ユーザー IL_mstaIL_msta
提出日時 2015-11-06 23:57:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,613 bytes
コンパイル時間 1,094 ms
コンパイル使用メモリ 107,816 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-11 14:31:53
合計ジャッジ時間 8,001 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
#include <sstream>
 
#include <algorithm>
#include <cmath>
 
#include <string>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <valarray>

#include<cassert>//assert();
//#include <random>//xAOJ
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
/////////
using namespace::std;
/////////
/////////

void solve(){
	int N,M;
	cin >> N >> M;
	vector< vector<int> > G(N,vector<int>(N,0));
	vector< vector<bool> > use(N,vector<bool>(N,false) );
	int A,B,C;
	for(int i=0;i<M;++i){
		cin >> A >> B >> C;
		G[A][B] = C;
	}
	vector<LD> ret(N,0.0);
	ret[0] = 1.0;
	queue<int> q;
	q.push(0);
	int id;
	bool flag;
	while( !q.empty() ){
		id = q.front();
		q.pop();
		flag = true;
		//配る番
		for(int j=0;j<N;++j){
			if( G[j][id] ){
				if( use[j][id] == false){
					flag = false;
					break;
				}
			}
		}
		if( flag == false){
			q.push(id);
			continue;
		}
		for(int i=0;i<N;++i){
			if( G[id][i] ){
				use[id][i] = true;
				q.push(i);
				if( ret[i] == 0){
					ret[i] = ret[id] * G[id][i]/100.0;
				}else{
					ret[i] = 1.0-(1-ret[i]) * (1-ret[id]*G[id][i]/100.0);
				}
			}
		}
	}
	cout << ret[N-1] << endl;
}

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    cout << setprecision(16);//
	
	//cpp
	solve();
	return 0;
}
0