結果

問題 No.1221 木 *= 3
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-09-06 12:40:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 2,813 bytes
コンパイル時間 4,373 ms
コンパイル使用メモリ 109,920 KB
実行使用メモリ 60,320 KB
最終ジャッジ日時 2023-08-19 13:49:58
合計ジャッジ時間 10,809 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,792 KB
testcase_01 AC 64 ms
23,692 KB
testcase_02 AC 62 ms
21,664 KB
testcase_03 AC 62 ms
21,636 KB
testcase_04 AC 62 ms
23,728 KB
testcase_05 AC 61 ms
21,596 KB
testcase_06 AC 62 ms
23,612 KB
testcase_07 AC 369 ms
53,956 KB
testcase_08 AC 346 ms
60,320 KB
testcase_09 AC 363 ms
53,284 KB
testcase_10 AC 364 ms
53,276 KB
testcase_11 AC 353 ms
53,180 KB
testcase_12 AC 358 ms
49,516 KB
testcase_13 AC 342 ms
53,104 KB
testcase_14 AC 361 ms
52,880 KB
testcase_15 AC 357 ms
48,980 KB
testcase_16 AC 355 ms
52,872 KB
testcase_17 AC 395 ms
51,756 KB
testcase_18 AC 368 ms
52,464 KB
testcase_19 AC 385 ms
53,240 KB
testcase_20 AC 386 ms
51,276 KB
testcase_21 AC 383 ms
53,280 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.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static List<int>[] li;
	static bool[] b;
	static int[] h,c,d;
	static long[][] dp;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		c=sc.Ia2;
		d=sc.Ia2;
		int n=s[0],m=n-1;
		li=new List<int>[n+1];
		b=new bool[n+1];
		h=new int[n+1];
		dp=new long[n+1][];
		for(int i=1;i<=n;i++){
			li[i]=new List<int>();
			dp[i]=new long[3];
		}
		for(int i=0;i<m;i++){
			var e=sc.Ia;
			li[e[0]].Add(e[1]);
			li[e[1]].Add(e[0]);
		}
		Fu(1,false);
		Console.WriteLine("{0}",dp[1].Max());
	}
	static void Fu(int a,bool g){
		b[a]=true;
		dp[a][0]=c[a];
		if(g){dp[a][1]=d[a];}
		for(int i=0;i<li[a].Count;i++){
			int u=li[a][i];
			if(!b[u]){
				Fu(u,true);
				dp[a][0]+=Max(dp[u][0],dp[u][2]);
				dp[a][1]+=Max(dp[u][0],dp[u][1]+d[a]);
				dp[a][2]+=Max(dp[u][0],dp[u][1]+d[a]);
			}
		}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0