結果

問題 No.408 五輪ピック
ユーザー 14番14番
提出日時 2016-09-01 20:10:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,906 ms / 5,000 ms
コード長 4,026 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 108,412 KB
実行使用メモリ 47,812 KB
最終ジャッジ日時 2023-08-09 19:51:47
合計ジャッジ時間 12,929 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
19,876 KB
testcase_01 AC 65 ms
21,768 KB
testcase_02 AC 64 ms
21,892 KB
testcase_03 AC 66 ms
23,808 KB
testcase_04 AC 66 ms
22,012 KB
testcase_05 AC 132 ms
33,800 KB
testcase_06 AC 106 ms
31,588 KB
testcase_07 AC 129 ms
33,836 KB
testcase_08 AC 114 ms
31,600 KB
testcase_09 AC 114 ms
30,384 KB
testcase_10 AC 105 ms
30,008 KB
testcase_11 AC 101 ms
29,904 KB
testcase_12 AC 138 ms
35,228 KB
testcase_13 AC 129 ms
30,472 KB
testcase_14 AC 77 ms
25,976 KB
testcase_15 AC 142 ms
35,500 KB
testcase_16 AC 138 ms
32,084 KB
testcase_17 AC 138 ms
29,868 KB
testcase_18 AC 136 ms
32,424 KB
testcase_19 AC 144 ms
35,316 KB
testcase_20 AC 83 ms
28,704 KB
testcase_21 AC 74 ms
23,916 KB
testcase_22 AC 97 ms
31,604 KB
testcase_23 AC 199 ms
46,856 KB
testcase_24 AC 167 ms
47,812 KB
testcase_25 AC 132 ms
32,936 KB
testcase_26 AC 151 ms
36,032 KB
testcase_27 AC 488 ms
35,540 KB
testcase_28 AC 2,906 ms
32,928 KB
testcase_29 AC 2,654 ms
32,880 KB
testcase_30 AC 66 ms
24,004 KB
testcase_31 AC 65 ms
21,952 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