結果
問題 | No.1207 グラフX |
ユーザー | fgwiebfaoish |
提出日時 | 2020-08-30 16:36:58 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,201 bytes |
コンパイル時間 | 1,111 ms |
コンパイル使用メモリ | 114,512 KB |
実行使用メモリ | 105,648 KB |
最終ジャッジ日時 | 2024-11-15 11:23:34 |
合計ジャッジ時間 | 38,038 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,021 ms
72,336 KB |
testcase_01 | AC | 1,027 ms
72,468 KB |
testcase_02 | AC | 1,021 ms
71,812 KB |
testcase_03 | AC | 1,034 ms
74,668 KB |
testcase_04 | AC | 1,020 ms
72,352 KB |
testcase_05 | AC | 907 ms
103,192 KB |
testcase_06 | AC | 909 ms
105,648 KB |
testcase_07 | AC | 904 ms
105,368 KB |
testcase_08 | AC | 725 ms
60,836 KB |
testcase_09 | AC | 840 ms
68,632 KB |
testcase_10 | AC | 886 ms
91,752 KB |
testcase_11 | AC | 899 ms
105,368 KB |
testcase_12 | AC | 737 ms
59,816 KB |
testcase_13 | AC | 363 ms
41,264 KB |
testcase_14 | AC | 984 ms
72,148 KB |
testcase_15 | AC | 827 ms
62,620 KB |
testcase_16 | AC | 354 ms
42,288 KB |
testcase_17 | AC | 630 ms
55,080 KB |
testcase_18 | AC | 569 ms
53,092 KB |
testcase_19 | AC | 546 ms
51,868 KB |
testcase_20 | AC | 1,029 ms
70,820 KB |
testcase_21 | AC | 83 ms
29,560 KB |
testcase_22 | AC | 618 ms
55,204 KB |
testcase_23 | AC | 689 ms
60,436 KB |
testcase_24 | AC | 503 ms
50,432 KB |
testcase_25 | AC | 1,016 ms
70,552 KB |
testcase_26 | AC | 753 ms
60,176 KB |
testcase_27 | AC | 904 ms
71,724 KB |
testcase_28 | AC | 829 ms
64,284 KB |
testcase_29 | AC | 869 ms
66,464 KB |
testcase_30 | AC | 388 ms
47,064 KB |
testcase_31 | AC | 306 ms
39,208 KB |
testcase_32 | AC | 363 ms
44,020 KB |
testcase_33 | AC | 367 ms
44,364 KB |
testcase_34 | AC | 786 ms
63,600 KB |
testcase_35 | AC | 86 ms
31,468 KB |
testcase_36 | AC | 780 ms
65,692 KB |
testcase_37 | AC | 651 ms
56,864 KB |
testcase_38 | AC | 174 ms
35,180 KB |
testcase_39 | AC | 404 ms
48,840 KB |
testcase_40 | WA | - |
testcase_41 | AC | 501 ms
51,240 KB |
testcase_42 | AC | 30 ms
26,304 KB |
testcase_43 | AC | 30 ms
26,176 KB |
testcase_44 | AC | 30 ms
22,068 KB |
testcase_45 | AC | 1,007 ms
72,104 KB |
testcase_46 | AC | 989 ms
70,296 KB |
testcase_47 | AC | 976 ms
72,092 KB |
testcase_48 | AC | 978 ms
74,152 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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; const long inf=long.MaxValue-1; static List<ValueTuple<int,int>>[] li; static bool[] b; static Mint[] d; static int[] pa; static long x; static int n; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; var g=new int[s[1]][]; n=s[0]; int m=n-1; x=s[2]; for(int i = 0;i<s[1];i++) {g[i]=sc.Ia;} Array.Sort(g,(u,v)=>u[2]-v[2]); Uf uf=new Uf(n+1); li=new List<ValueTuple<int,int>>[n+1]; b=new bool[n+1]; d=new Mint[n+1]; pa=new int[n+1]; for(int i=1;i<=n;i++){ li[i]=new List<ValueTuple<int,int>>(); } for(int i = 0;i<s[1];i++) { if(!uf.Same(g[i][0],g[i][1])){ uf.Union(g[i][0],g[i][1]); li[g[i][0]].Add(ValueTuple.Create(g[i][1],g[i][2])); li[g[i][1]].Add(ValueTuple.Create(g[i][0],g[i][2])); } } Fu(1); b=new bool[n+1]; Fu2(1,0); Mint ans=0; for(int i = 1;i<=n;i++) {ans+=d[i];} Console.WriteLine("{0}",ans); } static int Fu2(int a,int g){ b[a]=true; for(int i=0;i<li[a].Count;i++){ if(!b[li[a][i].Item1]){ var c=Fp(x,li[a][i].Item2); d[li[a][i].Item1]+=d[a]-d[li[a][i].Item1]-c*(pa[li[a][i].Item1]); Fu2(li[a][i].Item1,a); } } return 0; } static int Fu(int a){ b[a]=true; var p=1; for(int i=0;i<li[a].Count;i++){ if(!b[li[a][i].Item1]){ var k=Fu(li[a][i].Item1); var c=Fp(x,li[a][i].Item2); p+=k; d[a]+=c*k; d[a]+=d[li[a][i].Item1]; } } return pa[a]=p; } static long Fp(long x,long e){ long r=1; while(e>0){ if((e&1)>0){r*=x;r%=mod;} x=(x*x)%mod; e>>=1; } return r; } } public struct Mint{ const int mod=(int)1e9+7; private long d; public Mint(long d){this.d=d;} public static implicit operator Mint(long d){return new Mint(d%mod);} public static implicit operator bool(Mint d){return (int)d!=0;} public static explicit operator long(Mint d){return d.d;} public override string ToString(){return d.ToString();} public static Mint operator+(Mint a,long b){a.d=(a.d+b)%mod;return a;} public static Mint operator+(Mint a,Mint b){a.d=(a.d+b.d)%mod;return a;} public static Mint operator-(Mint a,long b){a.d=(mod+a.d-b)%mod;return a;} public static Mint operator-(Mint a,Mint b){a.d=(mod+a.d-b.d)%mod;return a;} public static Mint operator*(Mint a,long b){a.d=(a.d*b)%mod;return a;} public static Mint operator*(Mint a,Mint b){a.d=(a.d*b.d)%mod;return a;} public static Mint operator/(Mint a,long b){a.d=(a.d*Mi(b))%mod;return a;} public static Mint operator/(Mint a,Mint b){a.d=(a.d*Mi(b.d))%mod;return a;} private static long Mi(long a){ a=(a+mod)%mod; long b=mod,u=1,v=0; while(b>0){ long t=a/b; a-=t*b;(a,b)=(b,a); u-=t*v;(u,v)=(v,u); } u%=mod; if(u<0){u+=mod;} return u%mod; } } public class Uf{ private int[] arr,hi; public int all; public Uf(int n){ arr=new int[n]; hi=new int[n]; all=n; for(int i=0;i<n;i++){arr[i]=-1;} } public void Union(int a,int b){ a=Root(a); b=Root(b); if(a!=b){ if(hi[a]<hi[b]){(a,b)=(b,a);} arr[a]+=arr[b]; hi[a]=Max(hi[a],hi[b]+1); arr[b]=a; all--; } } public bool Same(int a,int b){return Root(a)==Root(b);} public int Size(int a){return -arr[Root(a)];} public int Root(int a){return arr[a]<0?a:arr[a]=Root(arr[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;} }