結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
sekiya9311
|
| 提出日時 | 2016-11-18 10:09:43 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 5,000 ms |
| コード長 | 2,317 bytes |
| コンパイル時間 | 2,480 ms |
| コンパイル使用メモリ | 108,800 KB |
| 実行使用メモリ | 19,200 KB |
| 最終ジャッジ日時 | 2024-11-26 05:50:39 |
| 合計ジャッジ時間 | 4,073 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.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));
}
}
sekiya9311