結果
問題 | No.1103 Directed Length Sum |
ユーザー | Y17 |
提出日時 | 2020-07-03 22:20:02 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 852 ms / 3,000 ms |
コード長 | 764 bytes |
コンパイル時間 | 1,610 ms |
コンパイル使用メモリ | 171,652 KB |
実行使用メモリ | 99,148 KB |
最終ジャッジ日時 | 2023-10-17 04:28:34 |
合計ジャッジ時間 | 9,955 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
34,916 KB |
testcase_01 | AC | 10 ms
34,916 KB |
testcase_02 | AC | 644 ms
99,148 KB |
testcase_03 | AC | 423 ms
43,376 KB |
testcase_04 | AC | 449 ms
45,424 KB |
testcase_05 | AC | 852 ms
53,120 KB |
testcase_06 | AC | 280 ms
41,756 KB |
testcase_07 | AC | 64 ms
36,560 KB |
testcase_08 | AC | 94 ms
37,432 KB |
testcase_09 | AC | 45 ms
35,956 KB |
testcase_10 | AC | 133 ms
38,364 KB |
testcase_11 | AC | 491 ms
46,388 KB |
testcase_12 | AC | 274 ms
41,828 KB |
testcase_13 | AC | 138 ms
38,460 KB |
testcase_14 | AC | 38 ms
35,696 KB |
testcase_15 | AC | 204 ms
40,304 KB |
testcase_16 | AC | 555 ms
47,800 KB |
testcase_17 | AC | 600 ms
48,364 KB |
testcase_18 | AC | 132 ms
38,336 KB |
testcase_19 | AC | 512 ms
46,668 KB |
testcase_20 | AC | 51 ms
36,172 KB |
testcase_21 | AC | 85 ms
37,192 KB |
testcase_22 | AC | 418 ms
44,512 KB |
testcase_23 | AC | 228 ms
40,668 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define int long long #define MOD 1000000007 vector<int> tree[1000010]; int rtree[1000010]; int dfs(int i, int j){ int ans = (j*(j+1))/2 % MOD; for(auto e : tree[i]){ ans += dfs(e, j+1); ans %= MOD; } return ans; } signed main(){ int n; cin >> n; int a, b; memset(rtree, -1, sizeof(rtree)); for(int i = 0;i < n-1;i++){ cin >> a >> b; a--; b--; tree[a].push_back(b); rtree[b] = a; } int root = 0; while(rtree[root] != -1) root = rtree[root]; cout << dfs(root, 0) << endl; return 0; }