結果

問題 No.1221 木 *= 3
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-09-06 12:40:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 406 ms / 2,000 ms
コード長 2,813 bytes
コンパイル時間 3,316 ms
コンパイル使用メモリ 112,368 KB
実行使用メモリ 63,984 KB
最終ジャッジ日時 2024-05-06 20:57:34
合計ジャッジ時間 10,710 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,880 KB
testcase_01 AC 30 ms
27,080 KB
testcase_02 AC 29 ms
24,916 KB
testcase_03 AC 29 ms
24,920 KB
testcase_04 AC 29 ms
24,532 KB
testcase_05 AC 29 ms
25,044 KB
testcase_06 AC 29 ms
24,748 KB
testcase_07 AC 402 ms
55,716 KB
testcase_08 AC 359 ms
63,984 KB
testcase_09 AC 388 ms
54,760 KB
testcase_10 AC 375 ms
54,640 KB
testcase_11 AC 389 ms
56,772 KB
testcase_12 AC 381 ms
57,100 KB
testcase_13 AC 371 ms
58,764 KB
testcase_14 AC 379 ms
56,680 KB
testcase_15 AC 369 ms
56,708 KB
testcase_16 AC 369 ms
52,480 KB
testcase_17 AC 392 ms
57,404 KB
testcase_18 AC 394 ms
58,100 KB
testcase_19 AC 401 ms
56,836 KB
testcase_20 AC 401 ms
54,736 KB
testcase_21 AC 406 ms
57,156 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