結果

問題 No.806 木を道に
ユーザー keymoon
提出日時 2019-02-24 16:43:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 4,628 ms
コンパイル使用メモリ 115,744 KB
実行使用メモリ 47,108 KB
最終ジャッジ日時 2024-07-07 03:41:07
合計ジャッジ時間 5,514 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;


class Ph
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[][] a = Enumerable.Repeat(0, n - 1).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        Assert(3 <= n && n <= 1e5);
        Assert(a.Length == n - 1);
        Assert(a.All(x => x.All(y => 1 <= y && y <= n)));
        var answer = Solve(n, a);
        Console.WriteLine(answer);
    }

    static int Solve(int n, int[][] a) => a.SelectMany(x => x).GroupBy(x => x).Sum(x => Max(0, x.Count() - 2));

    //直径から伸びている部分木の本数
    static int Lie1(int n, int[][] a)
    {
        return 0;
    }

    static void Assert(bool condition)
    {
        if (!condition) throw new Exception();
    }
}
0