結果

問題 No.1488 Max Score of the Tree
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2021-04-30 22:24:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 3,018 bytes
コンパイル時間 2,421 ms
コンパイル使用メモリ 108,636 KB
実行使用メモリ 24,016 KB
最終ジャッジ日時 2023-09-26 06:33:55
合計ジャッジ時間 6,815 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
22,068 KB
testcase_01 AC 92 ms
24,016 KB
testcase_02 AC 94 ms
21,908 KB
testcase_03 AC 94 ms
21,856 KB
testcase_04 AC 95 ms
23,924 KB
testcase_05 AC 61 ms
23,764 KB
testcase_06 AC 70 ms
21,668 KB
testcase_07 AC 81 ms
19,708 KB
testcase_08 AC 73 ms
21,696 KB
testcase_09 AC 72 ms
23,788 KB
testcase_10 AC 78 ms
19,780 KB
testcase_11 AC 94 ms
21,900 KB
testcase_12 AC 63 ms
21,604 KB
testcase_13 AC 68 ms
21,480 KB
testcase_14 AC 78 ms
21,776 KB
testcase_15 AC 73 ms
23,688 KB
testcase_16 AC 65 ms
21,572 KB
testcase_17 AC 69 ms
19,716 KB
testcase_18 AC 82 ms
23,932 KB
testcase_19 AC 74 ms
21,820 KB
testcase_20 AC 68 ms
21,572 KB
testcase_21 AC 66 ms
21,584 KB
testcase_22 AC 73 ms
21,752 KB
testcase_23 AC 62 ms
21,616 KB
testcase_24 AC 61 ms
21,528 KB
testcase_25 AC 61 ms
23,616 KB
testcase_26 AC 70 ms
22,032 KB
testcase_27 AC 64 ms
21,660 KB
testcase_28 AC 70 ms
23,668 KB
testcase_29 AC 67 ms
21,720 KB
testcase_30 AC 88 ms
21,916 KB
testcase_31 AC 98 ms
22,080 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;
using System.Threading;
using System.Runtime.CompilerServices;
static class Program{
	const int mod=(int)1e9+7;
	const long inf=long.MaxValue-1;
	static List<ValueTuple<int,int>>[] li;
	static bool[] b;
	static long[] h,d;
	static long ans=0;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0],m=n-1;
		li=new List<ValueTuple<int,int>>[n+1];
		b=new bool[n+1];
		h=new long[n+1];
		d=new long[n+1];
		for(int i=1;i<=n;i++){li[i]=new List<ValueTuple<int,int>>();}
		for(int i=0;i<m;i++){
			var e=sc.Ia;
			li[e[0]].Add(ValueTuple.Create(e[1],e[2]));
			li[e[1]].Add(ValueTuple.Create(e[0],e[2]));
		}
		Fu(1,0,0);
		var dp=new long[s[1]+1];
		for(int i = 2;i<=n;i++) {
			for(int j = s[1];j>=d[i];j--) {dp[j]=Max(dp[j],dp[j-d[i]]+h[i]);}
		}
		Console.WriteLine(ans+dp.Max());
	}
	static long Fu(int a,int g,int z){
		b[a]=true;
		long p=0;
		for(int i=0;i<li[a].Count;i++){
			if(!b[li[a][i].Item1]){p+=Fu(li[a][i].Item1,li[a][i].Item2,z+li[a][i].Item2);}
		}
		if(p==0){
			p=1;
			ans+=z;
		}
		h[a]=p*g;
		d[a]=g;
		return p;
	}
}

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