結果
問題 | No.92 逃走経路 |
ユーザー |
![]() |
提出日時 | 2017-01-12 07:13:04 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 4,543 ms / 5,000 ms |
コード長 | 3,132 bytes |
コンパイル時間 | 1,121 ms |
コンパイル使用メモリ | 112,692 KB |
実行使用メモリ | 57,052 KB |
最終ジャッジ日時 | 2024-12-21 10:24:50 |
合計ジャッジ時間 | 18,449 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
コンパイルメッセージ
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;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));}}