結果
問題 |
No.298 話の伝達
|
ユーザー |
![]() |
提出日時 | 2016-05-16 00:36:23 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,574 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 109,568 KB |
実行使用メモリ | 28,288 KB |
最終ジャッジ日時 | 2024-10-06 04:17:48 |
合計ジャッジ時間 | 8,344 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 WA * 4 TLE * 1 -- * 10 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int groupCount = inpt[0]; int relCount = inpt[1]; decimal[] wadai = new decimal[groupCount]; wadai = wadai.Select(a=>-1m).ToArray(); wadai[0] = 1; Dictionary<int, Dictionary<int, int>> dic = new Dictionary<int, Dictionary<int,int>>(); for(int i=0; i<relCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); if(!dic.ContainsKey(inpt[0])) { dic.Add(inpt[0], new Dictionary<int,int>()); } dic[inpt[0]].Add(inpt[1], inpt[2]); } Queue<int> task = new Queue<int>(); task.Enqueue(0); while (task.Count > 0) { int idx = task.Dequeue(); if(wadai[idx] < 0) { List<int> parents = dic.Where(a=>a.Value.ContainsKey(idx)).Select(b=>b.Key).ToList(); bool canSet = true; parents.ForEach(a=> canSet = (canSet && wadai[a] >= 0)); if(!canSet) { task.Enqueue(idx); continue; } decimal tutawaranai = 1; parents.ForEach((a)=>{ decimal tmpkakuritu = wadai[a] * dic[a][idx] / 100; tutawaranai = tutawaranai * (1 - tmpkakuritu); }); wadai[idx] = (1 - tutawaranai); } if(dic.ContainsKey(idx)) { dic[idx].Keys.ToList().ForEach(a=>task.Enqueue(a)); } } Console.WriteLine(wadai.Last()); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 5 5 0 1 30 0 2 70 1 3 20 2 4 80 3 4 90 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }