結果

問題 No.1221 木 *= 3
ユーザー keymoonkeymoon
提出日時 2020-09-04 22:29:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 1,681 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 115,168 KB
実行使用メモリ 72,484 KB
最終ジャッジ日時 2024-05-04 23:52:48
合計ジャッジ時間 6,461 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
25,264 KB
testcase_01 AC 29 ms
25,376 KB
testcase_02 AC 30 ms
27,372 KB
testcase_03 AC 30 ms
25,160 KB
testcase_04 AC 30 ms
27,252 KB
testcase_05 AC 30 ms
25,360 KB
testcase_06 AC 30 ms
25,548 KB
testcase_07 AC 276 ms
72,484 KB
testcase_08 AC 264 ms
70,068 KB
testcase_09 AC 275 ms
71,608 KB
testcase_10 AC 284 ms
69,448 KB
testcase_11 AC 286 ms
69,292 KB
testcase_12 AC 276 ms
61,220 KB
testcase_13 AC 267 ms
56,880 KB
testcase_14 AC 270 ms
58,672 KB
testcase_15 AC 275 ms
60,596 KB
testcase_16 AC 268 ms
60,720 KB
testcase_17 AC 290 ms
60,640 KB
testcase_18 AC 274 ms
57,388 KB
testcase_19 AC 294 ms
60,216 KB
testcase_20 AC 284 ms
58,708 KB
testcase_21 AC 280 ms
60,460 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var b = Console.ReadLine().Split().Select(long.Parse).ToArray();

        int[] degree = new int[n];
        List<int>[] graph = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < n - 1; i++)
        {
            var st = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            graph[st[0]].Add(st[1]);
            graph[st[1]].Add(st[0]);
            degree[st[0]]++;
            degree[st[1]]++;
        }

        Func<int, int, Tuple<long, long>> solve = null;
        solve = (int node, int parent) =>
        {
            var remainSum = 0L;
            var deleteSum = a[node];
            foreach (var adj in graph[node])
            {
                if (adj == parent) continue;
                var res = solve(adj, node);
                var remain = res.Item1;
                var delete = res.Item2;
                deleteSum += Max(remain, delete);
                remain += b[adj] + b[node];
                remainSum += Max(remain, delete);
            }
            return new Tuple<long, long>(remainSum, deleteSum);
        };
        var totalRes = solve(0, -1);
        Console.WriteLine(Max(totalRes.Item1, totalRes.Item2));
    }
}
0