結果

問題 No.1582 Vertexes vs Edges
コンテスト
ユーザー kakel-san
提出日時 2021-07-02 22:20:07
言語 C#(csc)
(csc 3.9.0)
コンパイル:
csc -langversion:latest -unsafe -warn:0 -o+ /r:System.Numerics.dll _filename_ -out:a.exe
実行:
/usr/bin/mono a.exe
結果
WA  
実行時間 -
コード長 1,220 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,124 ms
コンパイル使用メモリ 114,232 KB
実行使用メモリ 45,328 KB
最終ジャッジ日時 2026-03-18 23:35:02
合計ジャッジ時間 7,088 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
raw source code

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