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> dic = new Dictionary>(); for(int i=0; iint.Parse(a)).ToArray(); if(!dic.ContainsKey(inpt[0])) { dic.Add(inpt[0], new Dictionary()); } dic[inpt[0]].Add(inpt[1], inpt[2]); } Queue task = new Queue(); task.Enqueue(0); while (task.Count > 0) { int idx = task.Dequeue(); if(wadai[idx] < 0) { List 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(); } }