結果

問題 No.408 五輪ピック
ユーザー 14番14番
提出日時 2016-09-01 20:10:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,811 ms / 5,000 ms
コード長 4,026 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 115,396 KB
実行使用メモリ 51,072 KB
最終ジャッジ日時 2024-04-27 14:27:06
合計ジャッジ時間 10,107 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
25,588 KB
testcase_01 AC 32 ms
23,476 KB
testcase_02 AC 33 ms
23,728 KB
testcase_03 AC 33 ms
23,608 KB
testcase_04 AC 33 ms
25,512 KB
testcase_05 AC 101 ms
37,112 KB
testcase_06 AC 74 ms
36,448 KB
testcase_07 AC 101 ms
35,164 KB
testcase_08 AC 83 ms
34,952 KB
testcase_09 AC 86 ms
35,452 KB
testcase_10 AC 73 ms
35,152 KB
testcase_11 AC 73 ms
32,736 KB
testcase_12 AC 106 ms
38,484 KB
testcase_13 AC 99 ms
35,736 KB
testcase_14 AC 46 ms
27,412 KB
testcase_15 AC 115 ms
38,896 KB
testcase_16 AC 107 ms
39,300 KB
testcase_17 AC 108 ms
37,240 KB
testcase_18 AC 113 ms
37,372 KB
testcase_19 AC 119 ms
36,324 KB
testcase_20 AC 54 ms
34,004 KB
testcase_21 AC 42 ms
27,416 KB
testcase_22 AC 68 ms
35,036 KB
testcase_23 AC 183 ms
49,752 KB
testcase_24 AC 141 ms
51,072 KB
testcase_25 AC 105 ms
35,948 KB
testcase_26 AC 122 ms
39,136 KB
testcase_27 AC 457 ms
38,636 KB
testcase_28 AC 2,811 ms
37,884 KB
testcase_29 AC 2,554 ms
33,920 KB
testcase_30 AC 34 ms
25,260 KB
testcase_31 AC 34 ms
27,500 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.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;
        }

        Dictionary<int, Dictionary<int, bool>> from1 = new Dictionary<int,Dictionary<int,bool>>();
        Dictionary<int, Dictionary<int, bool>> to1 = new Dictionary<int,Dictionary<int,bool>>();

        bool ans = false;
        if (con.ContainsKey(1))
        {
            foreach (int pos1 in con[1].Keys)
            {
                if (con.ContainsKey(pos1))
                {
                    foreach (int pos2 in con[pos1].Keys)
                    {
                        if (pos2 == 1)
                        {
                            continue;
                        }
                        if (!from1.ContainsKey(pos1))
                        {
                            from1.Add(pos1, new Dictionary<int, bool>());
                        }
                        from1[pos1][pos2] = true;
                        if (!to1.ContainsKey(pos2))
                        {
                            to1.Add(pos2, new Dictionary<int, bool>());
                        }
                        to1[pos2][pos1] = true;
                    }
                }
            }
            foreach (int pos1 in from1.Keys)
            {
                foreach (int pos2 in from1[pos1].Keys)
                {
                    if (!con.ContainsKey(pos2))
                    {
                        break;
                    }
                    foreach (int pos3 in con[pos2].Keys)
                    {
                        if (pos3 == pos1 || !to1.ContainsKey(pos3))
                        {
                            continue;
                        }
                        foreach (int pos4 in to1[pos3].Keys)
                        {
                            if (pos4 == pos2 || pos4 == pos1)
                            {
                                continue;
                            }
                            ans = true;
                            break;
                        }
                        if (ans)
                        {
                            break;
                        }
                    }
                    if (ans)
                    {
                        break;
                    }
                }
                if (ans)
                {
                    break;
                }
            }
        }
        Console.WriteLine(ans ? "YES" : "NO");

    }


    private Dictionary<int, Dictionary<int, bool>> con = 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();
    }
}
0