結果

問題 No.92 逃走経路
ユーザー sekiya9311sekiya9311
提出日時 2016-11-18 10:09:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 2,317 bytes
コンパイル時間 3,550 ms
コンパイル使用メモリ 108,656 KB
実行使用メモリ 23,060 KB
最終ジャッジ日時 2023-08-17 09:58:28
合計ジャッジ時間 6,104 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
21,016 KB
testcase_01 AC 60 ms
20,848 KB
testcase_02 AC 61 ms
20,828 KB
testcase_03 AC 60 ms
22,880 KB
testcase_04 AC 60 ms
22,880 KB
testcase_05 AC 88 ms
20,828 KB
testcase_06 AC 84 ms
20,840 KB
testcase_07 AC 85 ms
22,876 KB
testcase_08 AC 69 ms
20,960 KB
testcase_09 AC 74 ms
18,928 KB
testcase_10 AC 91 ms
22,964 KB
testcase_11 AC 90 ms
20,896 KB
testcase_12 AC 94 ms
20,872 KB
testcase_13 AC 72 ms
20,892 KB
testcase_14 AC 74 ms
22,904 KB
testcase_15 AC 78 ms
23,060 KB
testcase_16 AC 78 ms
21,024 KB
testcase_17 AC 82 ms
20,860 KB
testcase_18 AC 81 ms
20,940 KB
testcase_19 AC 80 ms
20,948 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.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class mainClass
{
	static Scanner sc;
	static bool defret = false;
	public static void Main(string[] args)
	{
		sc = new Scanner();
		while (pre()) solve();
	}
	static bool pre()
	{
		defret = !defret;
		return defret;
	}
	static void solve()
	{
		var vec = sc.nextIntArray();
		int N = vec[0], M = vec[1], K = vec[2];
		var abc = new Tuple<int, int, int>[M];
		List<Tuple<int, int>>[] graph = new List<Tuple<int, int>>[N];
		for (int i = 0; i < N; i++)
		{
			graph[i] = new List<Tuple<int, int>>();
		}
		for (int i = 0; i < M; i++)
		{
			vec = sc.nextIntArray();
			vec[0]--;vec[1]--;
			graph[vec[0]].Add(Tuple.Create(vec[1], vec[2]));
			graph[vec[1]].Add(Tuple.Create(vec[0], vec[2]));
			abc[i] = Tuple.Create(vec[0], vec[1], vec[2]);
		}
		int[] d = sc.nextIntArray();
		bool[, ] dp = new bool[K, N];//[i][j] = i回目にjいる可能性があるか?
		foreach (var e in abc)
		{
			if (e.Item3 == d[0])
			{
				dp[0, e.Item1] = true;
				dp[0, e.Item2] = true;
			}
		}
		for (int i = 0; i < K - 1; i++)
		{
			for (int j = 0; j < N; j++)
			{
				if (!dp[i, j]) continue;
				foreach (var e in graph[j])
				{
					if (e.Item2 == d[i + 1])
					{
						dp[i + 1, e.Item1] = true;
					}
				}
			}
		}
		int ans = 0;
		List<int> ansList = new List<int>();
		for (int i = 0; i < N; i++)
		{
			if (dp[K - 1, i])
			{
				ans++;
				ansList.Add(i + 1);
			}
		}
		Console.WriteLine(ans);
		for (int i = 0; i < ansList.Count; i++)
		{
			Console.Write(ansList[i]);
			Console.Write((i == (int)ansList.Count - 1 ? "\n" : " "));
		}
	}
}

public class Scanner
{
	public Scanner() { }
	public string next()
	{
		return Console.ReadLine();
	}
	public int nextInt()
	{
		return int.Parse(next());
	}
	public double nextDouble()
	{
		return double.Parse(next());
	}
	public long nextLong()
	{
		return long.Parse(next());
	}
	public string[] nextArray()
	{
		return next().Split(' ');
	}
	public int[] nextIntArray()
	{
		return Array.ConvertAll(nextArray(), e => int.Parse(e));
	}
	public long[] nextLongArray()
	{
		return Array.ConvertAll(nextArray(), e => long.Parse(e));
	}
	public double[] nextDoubleArray()
	{
		return Array.ConvertAll(nextArray(), e => double.Parse(e));
	}
}
0