結果

問題 No.2532 Want Play More
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-04 19:16:06
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 471 ms / 2,000 ms
コード長 1,796 bytes
コンパイル時間 10,191 ms
コンパイル使用メモリ 158,328 KB
実行使用メモリ 216,116 KB
最終ジャッジ日時 2023-11-04 19:16:26
合計ジャッジ時間 18,966 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
32,888 KB
testcase_01 AC 471 ms
66,616 KB
testcase_02 AC 440 ms
66,676 KB
testcase_03 AC 417 ms
66,476 KB
testcase_04 AC 424 ms
66,568 KB
testcase_05 AC 411 ms
67,492 KB
testcase_06 AC 326 ms
96,040 KB
testcase_07 AC 84 ms
33,892 KB
testcase_08 AC 89 ms
35,340 KB
testcase_09 AC 86 ms
34,952 KB
testcase_10 AC 212 ms
62,900 KB
testcase_11 AC 214 ms
62,868 KB
testcase_12 AC 281 ms
64,124 KB
testcase_13 AC 231 ms
63,252 KB
testcase_14 AC 118 ms
45,176 KB
testcase_15 AC 414 ms
66,624 KB
testcase_16 AC 396 ms
68,152 KB
testcase_17 AC 86 ms
34,596 KB
testcase_18 AC 262 ms
63,664 KB
testcase_19 AC 381 ms
68,316 KB
testcase_20 AC 79 ms
32,884 KB
testcase_21 AC 80 ms
32,884 KB
testcase_22 AC 78 ms
32,924 KB
testcase_23 AC 79 ms
32,884 KB
testcase_24 AC 79 ms
32,884 KB
testcase_25 AC 79 ms
32,884 KB
testcase_26 AC 79 ms
32,884 KB
testcase_27 AC 80 ms
32,884 KB
testcase_28 AC 278 ms
216,116 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (115 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

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

class Program
{
    static int NN => int.Parse(ReadLine());
    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 n = NN;
        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]].Add(edge[1]);
            tree[edge[1]].Add(edge[0]);
        }
        var len1 = new int[n];
        var len2 = new int[n];
        DFS(-1, 0, 0, tree, len1, len2);
        WriteLine($"{len1[0]}\n{len2[0]}");
    }
    static void DFS(int prev, int cur, int dep, List<int>[] tree, int[] len1, int[] len2)
    {
        var max = 0;
        var min = int.MaxValue / 2;
        foreach (var next in tree[cur])
        {
            if (prev == next) continue;
            DFS(cur, next, dep + 1, tree, len1, len2);
            if (dep % 2 == 0)
            {
                max = Math.Max(max, len1[next] + 1);
                min = Math.Min(min, len2[next] + 1);
            }
            else
            {
                max = Math.Max(max, len2[next] + 1);
                min = Math.Min(min, len1[next] + 1);
            }
        }
        if (min == int.MaxValue / 2) min = 0;
        if (dep % 2 == 0)
        {
            len1[cur] = max;
            len2[cur] = min;
        }
        else
        {
            len1[cur] = min;
            len2[cur] = max;
        }
    }
}
0