結果

問題 No.92 逃走経路
ユーザー 14番14番
提出日時 2016-04-10 20:47:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 788 ms / 5,000 ms
コード長 3,337 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 115,504 KB
実行使用メモリ 51,896 KB
最終ジャッジ日時 2024-04-14 23:54:51
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 261 ms
31,160 KB
testcase_01 AC 29 ms
26,076 KB
testcase_02 AC 28 ms
24,340 KB
testcase_03 AC 29 ms
24,472 KB
testcase_04 AC 29 ms
24,496 KB
testcase_05 AC 168 ms
51,896 KB
testcase_06 AC 47 ms
24,724 KB
testcase_07 AC 45 ms
24,464 KB
testcase_08 AC 34 ms
24,748 KB
testcase_09 AC 86 ms
28,952 KB
testcase_10 AC 439 ms
28,976 KB
testcase_11 AC 494 ms
28,980 KB
testcase_12 AC 788 ms
42,508 KB
testcase_13 AC 53 ms
28,848 KB
testcase_14 AC 78 ms
31,032 KB
testcase_15 AC 137 ms
30,896 KB
testcase_16 AC 139 ms
30,892 KB
testcase_17 AC 226 ms
29,120 KB
testcase_18 AC 154 ms
28,852 KB
testcase_19 AC 103 ms
29,116 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.GetInt();

        int matiCount = inpt[0];

        int roadCount = inpt[1];

        int queryCount = inpt[2];

        List<Road> roadList = new List<Road>();

        for (int i = 0; i < roadCount; i++)
        {
            inpt = Reader.GetInt();
            Road rd = new Road(inpt[0], inpt[1], inpt[2]);
            roadList.Add(rd);
        }

        int[] history = Reader.GetInt();

        List<int> target = new List<int>();

        roadList.FindAll((a) =>
        {
            return (a.Cost == history[0]);
        }).ForEach((a) =>
        {
            if (!target.Contains(a.Mati1))
            {
                target.Add(a.Mati1);
            }
            if (!target.Contains(a.Mati2))
            {
                target.Add(a.Mati2);
            }
        });

        for (int i = 1; i < history.Length; i++)
        {
            List<int> nextTarget = new List<int>(); ;
            target.ForEach((a) => {
                roadList.FindAll((b) =>
                {
                    return (b.Mati1 == a || b.Mati2 == a) && b.Cost == history[i];
                }).ForEach((c) => {
                    if (c.Mati1 != a && (!nextTarget.Contains(c.Mati1)))
                    {
                        nextTarget.Add(c.Mati1);
                    } else if(c.Mati2 != a && (!nextTarget.Contains(c.Mati2))) {
                        nextTarget.Add(c.Mati2);
                    }
                });
            });
            target = nextTarget;
            if (nextTarget.Count == 0)
            {
                break;
            }
        }
        target.Sort();
        Console.WriteLine(target.Count);
        Console.WriteLine(string.Join<int>(" ", target)); 
    
    }

    public class Road
    {
        public int Mati1;
        public int Mati2;
        public int Cost;

        public Road(int m1, int m2, int c)
        {
            this.Mati1 = m1;
            this.Mati2 = m2;
            this.Cost = c;
        }
    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

3 2 2
1 2 10
1 2 20
10 20





 
";
        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();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0