結果
問題 | No.1221 木 *= 3 |
ユーザー | keymoon |
提出日時 | 2020-09-04 22:29:08 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 310 ms / 2,000 ms |
コード長 | 1,681 bytes |
コンパイル時間 | 2,080 ms |
コンパイル使用メモリ | 108,160 KB |
実行使用メモリ | 64,232 KB |
最終ジャッジ日時 | 2024-11-26 14:50:19 |
合計ジャッジ時間 | 7,923 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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)); } }