結果
問題 | No.1103 Directed Length Sum |
ユーザー | leaf_1415 |
提出日時 | 2020-07-03 21:47:52 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 510 ms / 3,000 ms |
コード長 | 1,150 bytes |
コンパイル時間 | 606 ms |
コンパイル使用メモリ | 82,520 KB |
実行使用メモリ | 121,764 KB |
最終ジャッジ日時 | 2023-10-17 00:31:19 |
合計ジャッジ時間 | 6,831 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
27,344 KB |
testcase_01 | AC | 9 ms
27,344 KB |
testcase_02 | AC | 319 ms
121,764 KB |
testcase_03 | AC | 168 ms
35,884 KB |
testcase_04 | AC | 276 ms
38,404 KB |
testcase_05 | AC | 510 ms
46,220 KB |
testcase_06 | AC | 163 ms
34,544 KB |
testcase_07 | AC | 38 ms
29,076 KB |
testcase_08 | AC | 70 ms
29,996 KB |
testcase_09 | AC | 28 ms
28,440 KB |
testcase_10 | AC | 80 ms
30,976 KB |
testcase_11 | AC | 299 ms
39,420 KB |
testcase_12 | AC | 167 ms
34,620 KB |
testcase_13 | AC | 77 ms
31,076 KB |
testcase_14 | AC | 23 ms
28,168 KB |
testcase_15 | AC | 124 ms
33,016 KB |
testcase_16 | AC | 341 ms
40,900 KB |
testcase_17 | AC | 352 ms
41,464 KB |
testcase_18 | AC | 84 ms
30,944 KB |
testcase_19 | AC | 306 ms
39,712 KB |
testcase_20 | AC | 31 ms
28,668 KB |
testcase_21 | AC | 50 ms
29,740 KB |
testcase_22 | AC | 241 ms
37,444 KB |
testcase_23 | AC | 158 ms
33,400 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:62:12: warning: ‘root’ may be used uninitialized in this function [-Wmaybe-uninitialized] 62 | dfs(root, 0); | ~~~^~~~~~~~~
ソースコード
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define mod 1000000007 using namespace std; typedef pair<llint, llint> P; llint n; vector<llint> G[1000005]; bool used[1000005]; llint ans; llint dfs(int v, llint d) { llint ret = 1; for(int i = 0; i < G[v].size(); i++){ ret += dfs(G[v][i], d+1); } ans += ret * d % mod, ans %= mod; return ret; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; llint u, v; for(int i = 1; i <= n-1; i++){ cin >> u >> v; G[u].push_back(v); used[v] = true; } llint root; for(int i = 1; i <= n; i++){ if(!used[i]) root = i; } dfs(root, 0); cout << ans << endl; return 0; }