結果
問題 | No.1207 グラフX |
ユーザー | kotatsugame |
提出日時 | 2020-10-07 23:43:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 333 ms / 2,000 ms |
コード長 | 3,321 bytes |
コンパイル時間 | 786 ms |
コンパイル使用メモリ | 77,824 KB |
実行使用メモリ | 36,852 KB |
最終ジャッジ日時 | 2024-07-20 04:27:11 |
合計ジャッジ時間 | 14,624 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 278 ms
22,012 KB |
testcase_01 | AC | 279 ms
22,032 KB |
testcase_02 | AC | 285 ms
21,988 KB |
testcase_03 | AC | 280 ms
21,872 KB |
testcase_04 | AC | 291 ms
21,880 KB |
testcase_05 | AC | 333 ms
36,724 KB |
testcase_06 | AC | 326 ms
36,852 KB |
testcase_07 | AC | 333 ms
36,720 KB |
testcase_08 | AC | 237 ms
16,732 KB |
testcase_09 | AC | 238 ms
19,288 KB |
testcase_10 | AC | 316 ms
29,552 KB |
testcase_11 | AC | 320 ms
36,728 KB |
testcase_12 | AC | 228 ms
17,972 KB |
testcase_13 | AC | 158 ms
11,264 KB |
testcase_14 | AC | 268 ms
21,316 KB |
testcase_15 | AC | 239 ms
18,464 KB |
testcase_16 | AC | 147 ms
12,096 KB |
testcase_17 | AC | 190 ms
16,092 KB |
testcase_18 | AC | 154 ms
16,468 KB |
testcase_19 | AC | 206 ms
13,688 KB |
testcase_20 | AC | 289 ms
21,592 KB |
testcase_21 | AC | 32 ms
9,728 KB |
testcase_22 | AC | 188 ms
16,504 KB |
testcase_23 | AC | 204 ms
18,184 KB |
testcase_24 | AC | 133 ms
15,592 KB |
testcase_25 | AC | 275 ms
21,580 KB |
testcase_26 | AC | 217 ms
18,448 KB |
testcase_27 | AC | 258 ms
20,112 KB |
testcase_28 | AC | 238 ms
19,300 KB |
testcase_29 | AC | 240 ms
20,008 KB |
testcase_30 | AC | 130 ms
13,616 KB |
testcase_31 | AC | 140 ms
10,736 KB |
testcase_32 | AC | 114 ms
13,944 KB |
testcase_33 | AC | 121 ms
13,744 KB |
testcase_34 | AC | 239 ms
18,300 KB |
testcase_35 | AC | 35 ms
9,728 KB |
testcase_36 | AC | 227 ms
19,164 KB |
testcase_37 | AC | 199 ms
16,696 KB |
testcase_38 | AC | 60 ms
11,220 KB |
testcase_39 | AC | 120 ms
14,372 KB |
testcase_40 | AC | 131 ms
9,856 KB |
testcase_41 | AC | 190 ms
13,860 KB |
testcase_42 | AC | 5 ms
9,600 KB |
testcase_43 | AC | 5 ms
9,728 KB |
testcase_44 | AC | 5 ms
9,600 KB |
testcase_45 | AC | 255 ms
22,012 KB |
testcase_46 | AC | 253 ms
21,880 KB |
testcase_47 | AC | 305 ms
21,884 KB |
testcase_48 | AC | 248 ms
22,040 KB |
コンパイルメッセージ
a.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp" #include<iostream> #include<vector> using namespace std; #line 3 "/home/kotatsugame/library/math/modint.cpp" #include<utility> template<int m> struct modint{ unsigned int x; constexpr modint()noexcept:x(){} constexpr modint(long long _x)noexcept:x((_x%=m)<0?_x+m:_x){} constexpr unsigned int val()const noexcept{return x;} constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;} constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;} constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;} constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;} constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;} constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;} constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;} constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();} constexpr modint operator+()const noexcept{return*this;} constexpr modint operator-()const noexcept{return modint()-*this;} constexpr modint pow(long long n)const noexcept { if(n<0)return pow(-n).inv(); modint x=*this,r=1; for(;n;x*=x,n>>=1)if(n&1)r*=x; return r; } constexpr modint inv()const noexcept { int s=x,t=m,x=1,u=0; while(t) { int k=s/t; s-=k*t; swap(s,t); x-=k*u; swap(x,u); } return modint(x); } constexpr modint operator+(const modint&a)const noexcept{return modint(*this)+=a;} constexpr modint operator-(const modint&a)const noexcept{return modint(*this)-=a;} constexpr modint operator*(const modint&a)const noexcept{return modint(*this)*=a;} constexpr modint operator/(const modint&a)const noexcept{return modint(*this)/=a;} constexpr bool operator==(const modint&a)const noexcept{return x==a.x;} constexpr bool operator!=(const modint&a)const noexcept{return x!=a.x;} friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;} friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;} }; #line 2 "/home/kotatsugame/library/datastructure/UF.cpp" struct UF{ int n; vector<int>parent,rank; UF(int n_=0):n(n_),parent(n_),rank(n_,1) { for(int i=0;i<n_;i++)parent[i]=i; } int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;} bool same(int a,int b){return find(a)==find(b);} bool unite(int a,int b) { a=find(a),b=find(b); if(a==b)return false; if(rank[a]<rank[b]) { parent[a]=b; rank[b]+=rank[a]; } else { parent[b]=a; rank[a]+=rank[b]; } return true; } int size(int a){return rank[find(a)];} }; #line 6 "a.cpp" using mint=modint<(int)1e9+7>; int N,M; mint X; vector<int>G[2<<17]; vector<pair<pair<int,int>,int> >E; int depth[2<<17],ch[2<<17]; int dfs(int u,int p,int d) { depth[u]=d; ch[u]=1; for(int v:G[u])if(v!=p) { ch[u]+=dfs(v,u,d+1); } return ch[u]; } main() { cin>>N>>M>>X; UF uf(N); for(int i=0;i<M;i++) { int x,y,z;cin>>x>>y>>z; x--,y--; if(uf.unite(x,y)) { G[x].push_back(y); G[y].push_back(x); E.push_back(make_pair(make_pair(x,y),z)); } } dfs(0,-1,0); mint ans=0; for(pair<pair<int,int>,int>e:E) { int u=e.first.first,v=e.first.second; if(depth[u]<depth[v])u=v; ans+=X.pow(e.second)*ch[u]*(N-ch[u]); } cout<<ans<<endl; }