結果

問題 No.1098 LCAs
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-06-26 23:29:03
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 636 ms / 2,000 ms
コード長 2,650 bytes
コンパイル時間 3,839 ms
コンパイル使用メモリ 109,976 KB
実行使用メモリ 75,640 KB
最終ジャッジ日時 2023-09-18 08:15:43
合計ジャッジ時間 12,729 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
22,784 KB
testcase_01 AC 63 ms
22,972 KB
testcase_02 AC 62 ms
20,876 KB
testcase_03 AC 63 ms
20,944 KB
testcase_04 AC 63 ms
20,892 KB
testcase_05 AC 62 ms
20,900 KB
testcase_06 AC 64 ms
20,736 KB
testcase_07 AC 63 ms
20,848 KB
testcase_08 AC 62 ms
20,832 KB
testcase_09 AC 62 ms
20,884 KB
testcase_10 AC 64 ms
20,912 KB
testcase_11 AC 64 ms
22,872 KB
testcase_12 AC 64 ms
20,908 KB
testcase_13 AC 64 ms
20,892 KB
testcase_14 AC 65 ms
20,932 KB
testcase_15 AC 64 ms
20,956 KB
testcase_16 AC 65 ms
23,020 KB
testcase_17 AC 64 ms
21,004 KB
testcase_18 AC 569 ms
55,268 KB
testcase_19 AC 564 ms
55,264 KB
testcase_20 AC 570 ms
57,316 KB
testcase_21 AC 567 ms
55,276 KB
testcase_22 AC 573 ms
57,320 KB
testcase_23 AC 508 ms
57,712 KB
testcase_24 AC 507 ms
57,784 KB
testcase_25 AC 498 ms
55,456 KB
testcase_26 AC 517 ms
55,796 KB
testcase_27 AC 512 ms
57,556 KB
testcase_28 AC 634 ms
74,268 KB
testcase_29 AC 636 ms
75,640 KB
testcase_30 AC 621 ms
74,300 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 long[] h,ans;
	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 long[n+1];
		ans=new long[n];
		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);
		Console.WriteLine("{0}",String.Join("\n",ans));
	}
	static void Fu(int a){
		b[a]=true;
		for(int i=0;i<li[a].Count;i++){
			if(!b[li[a][i]]){
				Fu(li[a][i]);
				ans[a-1]+=h[a]*h[li[a][i]]*2;
				h[a]+=h[li[a][i]];
			}
		}
		h[a]+=1;
		ans[a-1]+=h[a]*2-1;
	}
}

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