結果
| 問題 | No.408 五輪ピック |
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-09-01 18:38:44 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,574 bytes |
| 記録 | |
| コンパイル時間 | 3,375 ms |
| コンパイル使用メモリ | 112,852 KB |
| 実行使用メモリ | 40,560 KB |
| 最終ジャッジ日時 | 2024-11-15 17:00:51 |
| 合計ジャッジ時間 | 5,674 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 WA * 5 |
コンパイルメッセージ
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.Text;
using System.Linq;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int pointCount = inpt[0];
int connectCount = inpt[1];
for (int i = 0; i < connectCount; i++)
{
inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
if (!con.ContainsKey(inpt[0]))
{
con.Add(inpt[0], new Dictionary<int, bool>());
}
con[inpt[0]][inpt[1]] = true;
if (!con.ContainsKey(inpt[1]))
{
con.Add(inpt[1], new Dictionary<int, bool>());
}
con[inpt[1]][inpt[0]] = true;
}
bool ans = GetAns(1, 5);
Console.WriteLine(ans ? "YES" : "NO");
}
private bool GetAns(int pos, int remain)
{
if (!dic.ContainsKey(pos))
{
dic.Add(pos, new Dictionary<int, bool>());
}
if (dic[pos].ContainsKey(remain))
{
return dic[pos][remain];
}
if (remain == 0)
{
return pos == 1;
}
bool ans = false;
if (con.ContainsKey(pos))
{
foreach (int next in con[pos].Keys)
{
bool ret = this.GetAns(next, remain - 1);
if (ret)
{
ans = true;
break;
}
}
}
this.dic[pos].Add(remain, ans);
return ans;
}
private Dictionary<int, Dictionary<int, bool>> con = new Dictionary<int, Dictionary<int, bool>>();
private Dictionary<int, Dictionary<int, bool>> dic = new Dictionary<int, Dictionary<int, bool>>();
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
7 10
1 2
1 3
1 4
1 5
2 3
2 4
2 6
3 4
3 7
4 5
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
14番