結果

問題 No.92 逃走経路
ユーザー mbanmban
提出日時 2017-01-12 07:13:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 4,051 ms / 5,000 ms
コード長 3,132 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 108,428 KB
実行使用メモリ 50,168 KB
最終ジャッジ日時 2023-08-23 08:55:24
合計ジャッジ時間 19,095 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 802 ms
44,248 KB
testcase_01 AC 65 ms
22,680 KB
testcase_02 AC 65 ms
22,608 KB
testcase_03 AC 65 ms
22,612 KB
testcase_04 AC 65 ms
24,720 KB
testcase_05 AC 142 ms
22,772 KB
testcase_06 AC 92 ms
24,824 KB
testcase_07 AC 91 ms
24,756 KB
testcase_08 AC 89 ms
34,004 KB
testcase_09 AC 119 ms
44,860 KB
testcase_10 AC 3,284 ms
50,168 KB
testcase_11 AC 2,067 ms
45,584 KB
testcase_12 AC 4,051 ms
49,056 KB
testcase_13 AC 94 ms
29,008 KB
testcase_14 AC 521 ms
48,728 KB
testcase_15 AC 1,068 ms
47,920 KB
testcase_16 AC 432 ms
47,304 KB
testcase_17 AC 846 ms
47,100 KB
testcase_18 AC 429 ms
29,704 KB
testcase_19 AC 189 ms
26,796 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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static private Magatro M = new Magatro();
    static private void Main(string[]args)
    {
        M.Scan();
        M.Solve();
    }
}
public class Scanner
{
    private string[] S;
    private int Index;
    private char Separator;
    public Scanner(char separator = ' ')
    {
        Index = 0;
        Separator = separator;
    }
    private string[] Line()
    {
        return Console.ReadLine().Split(Separator);
    }
    public string Next()
    {
        string result;
        if (S == null || Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
public class Magatro
{
    private int N, M, K;
    private int[] d;
    private List<int>[] Load;
    private List<int>[] Fee;
    private HashSet<int> Anser = new HashSet<int>();
    public void Scan()
    {
        Scanner sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        K = sc.NextInt();
        Load = new List<int>[N];
        Fee = new List<int>[N];
        for(int i = 0; i < N; i++)
        {
            Load[i] = new List<int>();
            Fee[i] = new List<int>();
        }
        for (int i = 0; i < M; i++)
        {
            int a = sc.NextInt();
            int b = sc.NextInt();
            int c = sc.NextInt();
            Load[a - 1].Add(b-1);
            Load[b - 1].Add(a-1);
            Fee[a - 1].Add(c);
            Fee[b - 1].Add(c);
        }
        d = new int[K];
        for(int i = 0; i < K; i++)
        {
            d[i] = sc.NextInt();
        }
    }
    public void Solve()
    {
        for(int i = 0; i < N; i++)
        {
            HashSet<int>[] to = new HashSet<int>[K];
            for(int j = 0; j < K; j++)
            {
                to[j] = new HashSet<int>();
                if (j == 0)
                {
                    for (int k = 0; k < Load[i].Count; k++)
                    {
                        if (Fee[i][k] == d[j]) to[j].Add(Load[i][k]);
                    }
                }
                else
                {
                    foreach(int k in to[j - 1])
                    {
                        for(int l = 0; l < Load[k].Count; l++)
                        {
                            if (Fee[k][l] == d[j]) to[j].Add(Load[k][l]);
                        }
                    }
                }
            }
            foreach(int a in to[K - 1])
            {
                Anser.Add(a+1);
            }

        }
        int[] ans = Anser.ToArray();
        Array.Sort(ans);
        Console.WriteLine(ans.Length);
        Console.WriteLine(string.Join(" ", ans));
    }
}
0