結果
問題 | No.1103 Directed Length Sum |
ユーザー | firiexp |
提出日時 | 2020-07-03 21:52:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 529 ms / 3,000 ms |
コード長 | 2,447 bytes |
コンパイル時間 | 1,232 ms |
コンパイル使用メモリ | 109,248 KB |
実行使用メモリ | 93,296 KB |
最終ジャッジ日時 | 2024-09-17 00:20:14 |
合計ジャッジ時間 | 6,354 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 294 ms
93,296 KB |
testcase_03 | AC | 178 ms
35,360 KB |
testcase_04 | AC | 258 ms
27,876 KB |
testcase_05 | AC | 529 ms
45,740 KB |
testcase_06 | AC | 148 ms
19,248 KB |
testcase_07 | AC | 28 ms
7,168 KB |
testcase_08 | AC | 45 ms
9,216 KB |
testcase_09 | AC | 19 ms
6,944 KB |
testcase_10 | AC | 63 ms
11,484 KB |
testcase_11 | AC | 275 ms
30,072 KB |
testcase_12 | AC | 141 ms
19,432 KB |
testcase_13 | AC | 67 ms
11,612 KB |
testcase_14 | AC | 13 ms
6,948 KB |
testcase_15 | AC | 107 ms
16,032 KB |
testcase_16 | AC | 332 ms
33,352 KB |
testcase_17 | AC | 353 ms
34,760 KB |
testcase_18 | AC | 63 ms
11,260 KB |
testcase_19 | AC | 285 ms
30,900 KB |
testcase_20 | AC | 23 ms
6,940 KB |
testcase_21 | AC | 39 ms
8,696 KB |
testcase_22 | AC | 216 ms
25,848 KB |
testcase_23 | AC | 111 ms
16,864 KB |
ソースコード
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; template<u32 M = 1000000007> struct modint{ u32 val; modint(): val(0){} template<typename T> modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;} modint pow(ll k) const { modint res(1), x(val); while(k){ if(k&1) res *= x; x *= x; k >>= 1; } return res; } template<typename T> modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;} modint inv() const {return pow(M-2);} modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;} modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;} modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;} modint& operator/=(modint a){return (*this) *= a.inv();} modint operator+(modint a) const {return modint(val) +=a;} modint operator-(modint a) const {return modint(val) -=a;} modint operator*(modint a) const {return modint(val) *=a;} modint operator/(modint a) const {return modint(val) /=a;} modint operator-(){return modint(M-val);} bool operator==(const modint a) const {return val == a.val;} bool operator!=(const modint a) const {return val != a.val;} bool operator<(const modint a) const {return val < a.val;} }; using mint = modint<MOD>; int main() { int n; cin >> n; vector<int> deg(n); vector<vector<int>> G(n); for (int i = 0; i < n - 1; ++i) { int a, b; scanf("%d %d", &a, &b); a--; b--; G[a].emplace_back(b); deg[b]++; } mint a = 0; auto dfs = [&](int x, auto &&f) -> pair<mint, int> { pair<mint, int> ans{0, 1}; for (auto &&y : G[x]) { auto res = f(y, f); ans.first += res.first; ans.first += res.second; ans.second += res.second; } a += ans.first; return ans; }; for (int i = 0; i < n; ++i) { if(!deg[i]){ dfs(i, dfs); cout << a.val << "\n"; } } return 0; }