結果

問題 No.1103 Directed Length Sum
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-07-03 21:37:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,380 ms / 3,000 ms
コード長 2,684 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 111,856 KB
実行使用メモリ 226,836 KB
最終ジャッジ日時 2023-10-16 23:37:36
合計ジャッジ時間 22,748 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,136 KB
testcase_01 AC 27 ms
24,124 KB
testcase_02 AC 1,652 ms
226,836 KB
testcase_03 AC 1,188 ms
101,296 KB
testcase_04 AC 1,308 ms
83,708 KB
testcase_05 AC 2,380 ms
124,604 KB
testcase_06 AC 825 ms
64,312 KB
testcase_07 AC 183 ms
36,128 KB
testcase_08 AC 286 ms
40,736 KB
testcase_09 AC 121 ms
33,408 KB
testcase_10 AC 392 ms
45,612 KB
testcase_11 AC 1,444 ms
88,748 KB
testcase_12 AC 829 ms
64,624 KB
testcase_13 AC 407 ms
46,188 KB
testcase_14 AC 92 ms
32,240 KB
testcase_15 AC 646 ms
56,564 KB
testcase_16 AC 1,691 ms
96,084 KB
testcase_17 AC 1,760 ms
98,668 KB
testcase_18 AC 393 ms
45,552 KB
testcase_19 AC 1,483 ms
90,440 KB
testcase_20 AC 144 ms
34,340 KB
testcase_21 AC 253 ms
39,452 KB
testcase_22 AC 1,203 ms
78,944 KB
testcase_23 AC 677 ms
58,488 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;
	static long ans;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0],m=n-1,o=0;
		li=new List<int>[n+1];
		b=new bool[n+1];
		h=new long[n+1];
		//c=new long[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]);
			b[e[1]]=true;
		}
		for(int i = 1;i<=n;i++) {
			if(!b[i]){o=i;break;}
		}
		b=new bool[n+1];
		Fu(o);
		Console.WriteLine("{0}",ans%mod);
	}
	static long Fu(int a){
		long p=0;
		for(int i=0;i<li[a].Count;i++){
			long d=Fu(li[a][i]);
			p+=d+1+h[li[a][i]];
			h[a]+=h[li[a][i]]+1;
		}
		ans+=p;
		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