結果
問題 | No.1207 グラフX |
ユーザー | 沙耶花 |
提出日時 | 2020-08-30 13:23:58 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 351 ms / 2,000 ms |
コード長 | 1,500 bytes |
コンパイル時間 | 2,065 ms |
コンパイル使用メモリ | 207,352 KB |
実行使用メモリ | 31,144 KB |
最終ジャッジ日時 | 2023-08-09 11:45:02 |
合計ジャッジ時間 | 15,588 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 292 ms
17,212 KB |
testcase_01 | AC | 293 ms
17,116 KB |
testcase_02 | AC | 280 ms
17,164 KB |
testcase_03 | AC | 294 ms
17,164 KB |
testcase_04 | AC | 299 ms
17,456 KB |
testcase_05 | AC | 344 ms
31,104 KB |
testcase_06 | AC | 350 ms
31,112 KB |
testcase_07 | AC | 351 ms
31,144 KB |
testcase_08 | AC | 242 ms
11,340 KB |
testcase_09 | AC | 257 ms
14,436 KB |
testcase_10 | AC | 340 ms
24,192 KB |
testcase_11 | AC | 347 ms
31,108 KB |
testcase_12 | AC | 252 ms
12,252 KB |
testcase_13 | AC | 155 ms
5,320 KB |
testcase_14 | AC | 292 ms
16,464 KB |
testcase_15 | AC | 257 ms
13,304 KB |
testcase_16 | AC | 150 ms
6,072 KB |
testcase_17 | AC | 198 ms
10,752 KB |
testcase_18 | AC | 157 ms
10,924 KB |
testcase_19 | AC | 219 ms
7,836 KB |
testcase_20 | AC | 291 ms
16,968 KB |
testcase_21 | AC | 29 ms
4,380 KB |
testcase_22 | AC | 191 ms
10,956 KB |
testcase_23 | AC | 212 ms
12,248 KB |
testcase_24 | AC | 139 ms
10,096 KB |
testcase_25 | AC | 289 ms
16,716 KB |
testcase_26 | AC | 228 ms
12,924 KB |
testcase_27 | AC | 262 ms
15,124 KB |
testcase_28 | AC | 258 ms
14,676 KB |
testcase_29 | AC | 255 ms
14,944 KB |
testcase_30 | AC | 140 ms
7,876 KB |
testcase_31 | AC | 135 ms
4,660 KB |
testcase_32 | AC | 106 ms
8,240 KB |
testcase_33 | AC | 118 ms
7,784 KB |
testcase_34 | AC | 241 ms
13,076 KB |
testcase_35 | AC | 29 ms
4,380 KB |
testcase_36 | AC | 237 ms
14,616 KB |
testcase_37 | AC | 208 ms
11,440 KB |
testcase_38 | AC | 57 ms
5,248 KB |
testcase_39 | AC | 120 ms
9,096 KB |
testcase_40 | AC | 112 ms
4,380 KB |
testcase_41 | AC | 191 ms
8,128 KB |
testcase_42 | AC | 1 ms
4,380 KB |
testcase_43 | AC | 2 ms
4,376 KB |
testcase_44 | AC | 1 ms
4,380 KB |
testcase_45 | AC | 269 ms
17,152 KB |
testcase_46 | AC | 260 ms
17,448 KB |
testcase_47 | AC | 258 ms
17,316 KB |
testcase_48 | AC | 258 ms
17,284 KB |
コンパイルメッセージ
main.cpp:60:9: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’ 60 | int dfs(auto &E,int now,int p){ | ^~~~
ソースコード
#include <bits/stdc++.h> using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000 struct unionfind{ vector<int> data; vector<int> size; unionfind(int n){ for(int i=0;i<n;i++){ data.push_back(i); size.push_back(1); } } int find(int x){ if(data[x]==x)return x; return data[x]=find(data[x]); } bool unite(int x,int y){ x=find(x);y=find(y); if(x==y)return false; if(size[x]>size[y])swap(x,y); data[x]=y; size[y]+=size[x]; return true; } bool check(int x,int y){ return (find(x)==find(y)); } int get_size(int x){ int X = find(x); return size[X]; } }; int beki(long long a,long long b,int M = modulo){ int x = 1; while(b!=0){ if(b&1){ x=((long long)x*a)%M; } a=((long long)a*a)%M; b>>=1; } return x; } int gyakugen(int a){ return beki(a,modulo-2); } int N,M,X; int ans = 0; int dfs(auto &E,int now,int p){ int ret = 0; for(int i=0;i<E[now].size();i++){ int to = E[now][i].first; int z = E[now][i].second; if(to==p)continue; int t = dfs(E,to,now); int Y = mod(t*(N-t)); ans = mod(ans + mod(beki(X,z)*Y)); ret += t; } return ret+1; } int main(){ cin>>N>>M>>X; vector<vector<pair<int,int>>> E(N,vector<pair<int,int>>()); unionfind uf(N); for(int i=0;i<M;i++){ int x,y,z; cin>>x>>y>>z; x--;y--; if(uf.unite(x,y)){ E[x].emplace_back(y,z); E[y].emplace_back(x,z); } } dfs(E,0,-1); cout<<ans<<endl; return 0; }