結果

問題 No.1637 Easy Tree Query
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2021-08-06 23:01:52
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 2,752 bytes
コンパイル時間 4,726 ms
コンパイル使用メモリ 110,740 KB
実行使用メモリ 46,648 KB
最終ジャッジ日時 2023-10-17 05:14:38
合計ジャッジ時間 13,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,228 KB
testcase_01 AC 26 ms
24,224 KB
testcase_02 AC 283 ms
46,648 KB
testcase_03 AC 26 ms
24,228 KB
testcase_04 AC 119 ms
34,488 KB
testcase_05 AC 211 ms
37,404 KB
testcase_06 AC 158 ms
34,228 KB
testcase_07 AC 80 ms
29,808 KB
testcase_08 AC 99 ms
33,460 KB
testcase_09 AC 227 ms
39,384 KB
testcase_10 AC 112 ms
32,392 KB
testcase_11 AC 273 ms
42,144 KB
testcase_12 AC 249 ms
40,288 KB
testcase_13 AC 71 ms
31,612 KB
testcase_14 AC 191 ms
37,852 KB
testcase_15 AC 274 ms
41,888 KB
testcase_16 AC 265 ms
41,176 KB
testcase_17 AC 92 ms
31,780 KB
testcase_18 AC 201 ms
36,900 KB
testcase_19 AC 204 ms
37,536 KB
testcase_20 AC 264 ms
40,572 KB
testcase_21 AC 160 ms
35,920 KB
testcase_22 AC 308 ms
43,912 KB
testcase_23 AC 96 ms
32,288 KB
testcase_24 AC 154 ms
35,256 KB
testcase_25 AC 213 ms
37,304 KB
testcase_26 AC 277 ms
41,188 KB
testcase_27 AC 342 ms
44,424 KB
testcase_28 AC 173 ms
35,036 KB
testcase_29 AC 234 ms
38,624 KB
testcase_30 AC 128 ms
35,196 KB
testcase_31 AC 145 ms
32,744 KB
testcase_32 AC 125 ms
33,668 KB
testcase_33 AC 189 ms
35,764 KB
testcase_34 AC 156 ms
43,780 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;
	static List<int>[] li;
	static bool[] b;
	static int[] h;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0],m=n-1;
		li=new List<int>[n+1];
		b=new bool[n+1];
		h=new int[n+1];
		for(int i=1;i<=n;i++){li[i]=new List<int>();}
		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);
		long ans=0;
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<s[1];i++) {
			var e=sc.La;
			ans+=h[e[0]]*e[1];
			sb.Append(ans+"\n");
		}
		Console.Write(sb);
	}
	static void Fu(int a){
		b[a]=true;
		h[a]=1;
		for(int i=0;i<li[a].Count;i++){
			if(!b[li[a][i]]){
				Fu(li[a][i]);
				h[a]+=h[li[a][i]];
			}
		}
	}
}

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