結果

問題 No.1582 Vertexes vs Edges
ユーザー 👑 kakel-sankakel-san
提出日時 2021-07-02 22:40:36
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,245 bytes
コンパイル時間 1,141 ms
コンパイル使用メモリ 70,436 KB
実行使用メモリ 40,116 KB
最終ジャッジ日時 2023-09-11 23:02:38
合計ジャッジ時間 7,913 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
23,716 KB
testcase_01 AC 64 ms
21,732 KB
testcase_02 AC 67 ms
23,904 KB
testcase_03 AC 64 ms
21,608 KB
testcase_04 AC 68 ms
23,728 KB
testcase_05 AC 177 ms
38,100 KB
testcase_06 AC 70 ms
21,768 KB
testcase_07 AC 84 ms
29,252 KB
testcase_08 AC 120 ms
29,896 KB
testcase_09 AC 172 ms
37,360 KB
testcase_10 AC 134 ms
34,520 KB
testcase_11 AC 73 ms
21,800 KB
testcase_12 AC 107 ms
27,336 KB
testcase_13 AC 142 ms
31,876 KB
testcase_14 AC 146 ms
34,112 KB
testcase_15 AC 180 ms
35,908 KB
testcase_16 AC 119 ms
33,068 KB
testcase_17 AC 143 ms
34,376 KB
testcase_18 AC 193 ms
36,928 KB
testcase_19 AC 139 ms
33,380 KB
testcase_20 AC 137 ms
34,932 KB
testcase_21 AC 124 ms
31,428 KB
testcase_22 AC 179 ms
37,280 KB
testcase_23 AC 106 ms
30,424 KB
testcase_24 AC 83 ms
28,988 KB
testcase_25 AC 124 ms
29,996 KB
testcase_26 AC 107 ms
29,440 KB
testcase_27 AC 174 ms
38,268 KB
testcase_28 AC 94 ms
26,568 KB
testcase_29 AC 153 ms
34,368 KB
testcase_30 AC 119 ms
32,584 KB
testcase_31 AC 159 ms
34,392 KB
testcase_32 AC 106 ms
30,760 KB
testcase_33 AC 210 ms
40,116 KB
testcase_34 AC 214 ms
39,996 KB
testcase_35 AC 219 ms
39,920 KB
testcase_36 AC 63 ms
21,656 KB
testcase_37 AC 64 ms
21,784 KB
testcase_38 AC 64 ms
19,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class yuki302
{
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat<int>(0, n).Select(_ => NList).ToArray();
    static void Main()
    {
        var n = int.Parse(ReadLine());
        var map = NMap(n - 1);

        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] - 1].Add(edge[1] - 1);
            tree[edge[1] - 1].Add(edge[0] - 1);
        }

        var list = Enumerable.Repeat(int.MaxValue, n).ToArray();
        DFS(-1, 0, tree, list);
        WriteLine(list.Count(c => c % 2 == 1));
    }
    static int DFS(int prev, int pos, List<int>[] tree, int[] list)
    {
        var val = int.MaxValue;
        if (tree[pos].Count == 1 && tree[pos][0] == prev)
        {
            val = 1;
        }
        else foreach (var next in tree[pos])
        {
            if (next == prev) continue;
            val = Math.Min(val, DFS(pos, next, tree, list));
        }
        val = (val + 1) % 2;
        list[pos] = val;
        return val;
    }
}
0