結果

問題 No.2202 贅沢てりたまチキン
ユーザー 👑 kakel-sankakel-san
提出日時 2023-02-03 21:41:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 67,548 KB
実行使用メモリ 80,364 KB
最終ジャッジ日時 2023-09-15 17:21:14
合計ジャッジ時間 9,278 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,776 KB
testcase_01 AC 63 ms
21,856 KB
testcase_02 AC 63 ms
21,836 KB
testcase_03 AC 61 ms
21,732 KB
testcase_04 AC 63 ms
23,824 KB
testcase_05 AC 62 ms
23,880 KB
testcase_06 AC 62 ms
21,724 KB
testcase_07 AC 62 ms
19,748 KB
testcase_08 AC 62 ms
21,796 KB
testcase_09 AC 63 ms
21,944 KB
testcase_10 AC 78 ms
34,540 KB
testcase_11 AC 61 ms
21,980 KB
testcase_12 AC 63 ms
19,764 KB
testcase_13 AC 62 ms
21,740 KB
testcase_14 AC 353 ms
80,364 KB
testcase_15 AC 355 ms
78,176 KB
testcase_16 AC 309 ms
58,644 KB
testcase_17 AC 311 ms
58,624 KB
testcase_18 AC 177 ms
38,868 KB
testcase_19 AC 222 ms
51,220 KB
testcase_20 AC 330 ms
53,260 KB
testcase_21 AC 329 ms
55,324 KB
testcase_22 AC 247 ms
38,080 KB
testcase_23 AC 265 ms
38,248 KB
testcase_24 AC 255 ms
34,452 KB
testcase_25 AC 391 ms
53,296 KB
testcase_26 AC 350 ms
65,696 KB
testcase_27 AC 340 ms
69,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var map = NMap(m);
        var tree = new List<int>[n];
        for (var i = 0; i < tree.Length; ++i) tree[i] = new List<int>();
        foreach (var edge in map)
        {
            tree[edge[0]].Add(edge[1]);
            tree[edge[1]].Add(edge[0]);
        }
        var colors = new int[n];
        for (var i = 0; i < n; ++i)
        {
            if (DFS(i, 1, tree, colors))
            {
                WriteLine("No");
                return;
            }
        }
        WriteLine("Yes");
    }
    static bool DFS(int cur, int color, List<int>[] tree, int[] colors)
    {
        colors[cur] = color;
        foreach (var next in tree[cur])
        {
            if (colors[next] != 0)
            {
                if (colors[cur] == colors[next]) return false;
            }
            else
            {
                if (!DFS(next, -color, tree, colors)) return false;
            }
        }
        return true;
    }
}
0