結果

問題 No.298 話の伝達
ユーザー 14番14番
提出日時 2016-05-16 00:36:23
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,574 bytes
コンパイル時間 1,041 ms
コンパイル使用メモリ 109,056 KB
実行使用メモリ 28,672 KB
最終ジャッジ日時 2024-04-15 22:18:49
合計ジャッジ時間 8,157 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 40 ms
19,712 KB
testcase_02 AC 39 ms
19,584 KB
testcase_03 AC 41 ms
19,712 KB
testcase_04 WA -
testcase_05 AC 40 ms
19,456 KB
testcase_06 WA -
testcase_07 AC 39 ms
19,584 KB
testcase_08 AC 39 ms
19,712 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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();
    }
}
0