結果
問題 | No.1207 グラフX |
ユーザー | milanis48663220 |
提出日時 | 2020-08-31 01:54:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 210 ms / 2,000 ms |
コード長 | 3,323 bytes |
コンパイル時間 | 1,131 ms |
コンパイル使用メモリ | 88,668 KB |
実行使用メモリ | 31,104 KB |
最終ジャッジ日時 | 2024-11-15 16:15:26 |
合計ジャッジ時間 | 9,939 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 162 ms
20,044 KB |
testcase_01 | AC | 158 ms
20,040 KB |
testcase_02 | AC | 165 ms
19,332 KB |
testcase_03 | AC | 161 ms
19,316 KB |
testcase_04 | AC | 167 ms
19,304 KB |
testcase_05 | AC | 210 ms
30,976 KB |
testcase_06 | AC | 210 ms
30,976 KB |
testcase_07 | AC | 207 ms
30,976 KB |
testcase_08 | AC | 127 ms
15,616 KB |
testcase_09 | AC | 140 ms
16,992 KB |
testcase_10 | AC | 202 ms
25,472 KB |
testcase_11 | AC | 203 ms
31,104 KB |
testcase_12 | AC | 127 ms
15,872 KB |
testcase_13 | AC | 69 ms
11,392 KB |
testcase_14 | AC | 160 ms
18,852 KB |
testcase_15 | AC | 139 ms
16,768 KB |
testcase_16 | AC | 71 ms
11,648 KB |
testcase_17 | AC | 108 ms
14,592 KB |
testcase_18 | AC | 93 ms
14,336 KB |
testcase_19 | AC | 99 ms
13,568 KB |
testcase_20 | AC | 157 ms
19,088 KB |
testcase_21 | AC | 15 ms
8,832 KB |
testcase_22 | AC | 107 ms
14,720 KB |
testcase_23 | AC | 118 ms
15,616 KB |
testcase_24 | AC | 82 ms
13,696 KB |
testcase_25 | AC | 159 ms
18,976 KB |
testcase_26 | AC | 122 ms
16,256 KB |
testcase_27 | AC | 146 ms
18,020 KB |
testcase_28 | AC | 135 ms
17,172 KB |
testcase_29 | AC | 140 ms
17,604 KB |
testcase_30 | AC | 68 ms
12,288 KB |
testcase_31 | AC | 57 ms
11,008 KB |
testcase_32 | AC | 60 ms
12,288 KB |
testcase_33 | AC | 64 ms
12,204 KB |
testcase_34 | AC | 132 ms
16,640 KB |
testcase_35 | AC | 15 ms
8,704 KB |
testcase_36 | AC | 130 ms
16,772 KB |
testcase_37 | AC | 109 ms
15,228 KB |
testcase_38 | AC | 32 ms
10,112 KB |
testcase_39 | AC | 68 ms
12,668 KB |
testcase_40 | AC | 45 ms
9,984 KB |
testcase_41 | AC | 89 ms
13,184 KB |
testcase_42 | AC | 4 ms
8,064 KB |
testcase_43 | AC | 4 ms
8,064 KB |
testcase_44 | AC | 5 ms
8,192 KB |
testcase_45 | AC | 154 ms
19,292 KB |
testcase_46 | AC | 151 ms
19,416 KB |
testcase_47 | AC | 153 ms
19,424 KB |
testcase_48 | AC | 149 ms
19,164 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; struct UnionFind { vector<int> data; UnionFind(int size) : data(size, -1) { } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; const ll MOD = 1000000007; class ModInt{ public: ll v; ModInt(ll _v = 0){ v = _v; } ModInt operator+(ll n){ return ModInt((v+n)%MOD); } ModInt operator-(ll n){ return ModInt((v-n+MOD)%MOD); } ModInt operator*(ll n){ return ModInt((v*n)%MOD); } ModInt operator/(ll n){ return ModInt((ModInt(n).inv()*v).v%MOD); } void operator+=(ll n){ v = (v+n)%MOD; } void operator-=(ll n){ v = (v-n+MOD)%MOD; } void operator*=(ll n){ v = (v*n)%MOD; } ModInt operator+(ModInt n){ return ModInt((v+n.v)%MOD); } ModInt operator-(ModInt n){ return ModInt((v-n.v+MOD)%MOD); } ModInt operator*(ModInt n){ return ModInt((v*n.v)%MOD); } ModInt operator/(ModInt n){ return ModInt((n.inv()*v).v%MOD); } void operator+=(ModInt n){ v = (v+n.v)%MOD; } void operator-=(ModInt n){ v = (v-n.v+MOD)%MOD; } void operator*=(ModInt n){ v = (v*n.v)%MOD; } void operator=(ModInt n){ v = n.v; } void operator=(ll n){ v = n; } ModInt inv(){ if(v == 1) return ModInt(1); else return ModInt(MOD-ModInt(MOD%v).inv().v*(MOD/v)%MOD); } }; ostream& operator<<(ostream& os, const ModInt& m){ os << m.v; return os; } istream & operator >> (istream &in, ModInt &m){ in >> m.v; return in; } ModInt pow(ModInt a, ll n) { ModInt ans = 1; ModInt tmp = a; for (int i = 0; i <= 60; i++) { ll m = (ll)1 << i; if (m & n) { ans *= tmp; } tmp *= tmp; } return ans; } ll N, M, X; ModInt ans = 0; int x[200000], y[200000], z[200000]; bool used[200000]; int depth[200000]; int ch[200000]; vector<int> G[200000]; bool used_dfs[200000]; void dfs(int v){ used_dfs[v] = true; ch[v] = 1; for(int to: G[v]){ if(!used_dfs[to]) { dfs(to); ch[v] += ch[to]; } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N >> M >> X; UnionFind uf(N); for(int i = 0; i < M; i++){ cin >> x[i] >> y[i] >> z[i]; x[i]--; y[i]--; int rx = uf.root(x[i]), ry = uf.root(y[i]); if(rx != ry){ used[i] = true; G[x[i]].push_back(y[i]); G[y[i]].push_back(x[i]); uf.unionSet(x[i], y[i]); } } dfs(0); for(int i = 0; i < M; i++){ if(used[i]){ if(ch[x[i]] > ch[y[i]]) swap(x[i], y[i]); ans += pow(X, z[i])*ch[x[i]]*(N-ch[x[i]]); } } cout << ans << endl; }