結果

問題 No.92 逃走経路
ユーザー sekiya9311sekiya9311
提出日時 2016-11-18 09:58:49
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,333 bytes
コンパイル時間 5,084 ms
コンパイル使用メモリ 107,540 KB
実行使用メモリ 23,036 KB
最終ジャッジ日時 2023-08-17 09:57:59
合計ジャッジ時間 6,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 57 ms
20,784 KB
testcase_02 AC 58 ms
20,736 KB
testcase_03 AC 57 ms
20,828 KB
testcase_04 AC 57 ms
20,868 KB
testcase_05 AC 85 ms
20,868 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 65 ms
21,048 KB
testcase_09 AC 70 ms
20,864 KB
testcase_10 AC 88 ms
20,992 KB
testcase_11 AC 87 ms
20,944 KB
testcase_12 AC 91 ms
20,916 KB
testcase_13 AC 69 ms
22,956 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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];
		int[,] cost = new int[N, N];
		List<int>[] graph = new List<int>[N];
		for (int i = 0; i < N; i++)
		{
			graph[i] = new List<int>();
		}
		for (int i = 0; i < M; i++)
		{
			vec = sc.nextIntArray();
			vec[0]--;vec[1]--;
			graph[vec[0]].Add(vec[1]);
			graph[vec[1]].Add(vec[0]);
			cost[vec[0], vec[1]] = vec[2];
			cost[vec[1], 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 (cost[j, e] == d[i + 1])
					{
						dp[i + 1, e] = 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