結果

問題 No.1582 Vertexes vs Edges
ユーザー 👑 kakel-sankakel-san
提出日時 2021-07-02 22:20:07
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,220 bytes
コンパイル時間 1,570 ms
コンパイル使用メモリ 62,272 KB
実行使用メモリ 41,104 KB
最終ジャッジ日時 2023-09-11 22:25:42
合計ジャッジ時間 8,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,672 KB
testcase_01 AC 65 ms
23,744 KB
testcase_02 AC 66 ms
23,736 KB
testcase_03 AC 66 ms
21,584 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 71 ms
21,624 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 66 ms
21,648 KB
testcase_37 AC 66 ms
21,716 KB
testcase_38 AC 66 ms
23,628 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 = 0;
        }
        else foreach (var next in tree[pos])
        {
            if (next == prev) continue;
            val = Math.Min(val, DFS(pos, next, tree, list) + 1);
        }
        list[pos] = val;
        return val;
    }
}
0