結果
問題 | No.1207 グラフX |
ユーザー | fgwiebfaoish |
提出日時 | 2020-08-30 16:12:10 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,852 bytes |
コンパイル時間 | 2,461 ms |
コンパイル使用メモリ | 116,648 KB |
実行使用メモリ | 98,988 KB |
最終ジャッジ日時 | 2024-11-15 10:54:07 |
合計ジャッジ時間 | 31,068 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 693 ms
98,988 KB |
testcase_06 | AC | 698 ms
93,308 KB |
testcase_07 | AC | 685 ms
93,300 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 708 ms
93,288 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 27 ms
18,048 KB |
testcase_43 | AC | 27 ms
18,048 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
コンパイルメッセージ
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 long x; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; var g=new int[s[1]][]; int n=s[0],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]; 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); Mint ans=0; for(int i = 1;i<=n;i++) {ans+=d[i];} Console.WriteLine("{0}",ans); } 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 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;} }