結果
問題 | No.92 逃走経路 |
ユーザー | nanophoto12 |
提出日時 | 2014-12-14 15:23:01 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 530 ms / 5,000 ms |
コード長 | 3,052 bytes |
コンパイル時間 | 5,510 ms |
コンパイル使用メモリ | 104,728 KB |
実行使用メモリ | 59,108 KB |
最終ジャッジ日時 | 2023-09-02 14:30:11 |
合計ジャッジ時間 | 8,775 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 146 ms
34,816 KB |
testcase_01 | AC | 76 ms
23,984 KB |
testcase_02 | AC | 78 ms
21,964 KB |
testcase_03 | AC | 75 ms
23,892 KB |
testcase_04 | AC | 75 ms
21,860 KB |
testcase_05 | AC | 422 ms
43,872 KB |
testcase_06 | AC | 85 ms
24,016 KB |
testcase_07 | AC | 85 ms
22,128 KB |
testcase_08 | AC | 84 ms
22,048 KB |
testcase_09 | AC | 157 ms
40,748 KB |
testcase_10 | AC | 486 ms
55,004 KB |
testcase_11 | AC | 442 ms
42,664 KB |
testcase_12 | AC | 530 ms
59,108 KB |
testcase_13 | AC | 125 ms
34,468 KB |
testcase_14 | AC | 143 ms
36,692 KB |
testcase_15 | AC | 150 ms
37,196 KB |
testcase_16 | AC | 142 ms
36,592 KB |
testcase_17 | AC | 139 ms
34,616 KB |
testcase_18 | AC | 111 ms
28,728 KB |
testcase_19 | AC | 98 ms
29,844 KB |
コンパイルメッセージ
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.Generic; using System.Linq; using System.Text; namespace Yukicoder { class Program { private class Edge { private readonly int _from; private readonly int _to; public Edge(int from, int to) { _from = @from; _to = to; } public int From { get { return _from; } } public int To { get { return _to; } } } static void Main(string[] args) { var line = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var n = line[0]; var m = line[1]; var k = line[2]; Dictionary<long, List<Edge>> map = new Dictionary<long, List<Edge>>(); for (int i = 0; i < m; i++) { var edge = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); if (!map.ContainsKey(edge[2])) { map.Add(edge[2], new List<Edge>()); } map[edge[2]].Add(new Edge((int)edge[0], (int)edge[1])); } var history = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var list = new List<Dictionary<int, List<int>>>(); for (int i = 0; i < history.Length; i++) { var cost = history[i]; var candidates = new Dictionary<int, List<int>>(); for (int j = 0; j < map[cost].Count; j++) { if (!candidates.ContainsKey(map[cost][j].From)) { candidates.Add(map[cost][j].From, new List<int>()); } candidates[map[cost][j].From].Add(map[cost][j].To); if (!candidates.ContainsKey(map[cost][j].To)) { candidates.Add(map[cost][j].To, new List<int>()); } candidates[map[cost][j].To].Add(map[cost][j].From); } list.Add(candidates); } int[] previous = list[0].SelectMany(element=>element.Value).Distinct().ToArray(); for (int i = 1; i < list.Count; i++) { List<int> nexts = new List<int>(); for (int j = 0; j < previous.Length; j++) { if (list[i].ContainsKey(previous[j])) { nexts.AddRange(list[i][previous[j]]); } } previous = nexts.Distinct().ToArray(); } Array.Sort(previous); Console.WriteLine(previous.Length); Console.WriteLine(string.Join(" ",previous)); } } }