結果
問題 | No.1103 Directed Length Sum |
ユーザー | Y17 |
提出日時 | 2020-07-03 22:19:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 721 bytes |
コンパイル時間 | 1,456 ms |
コンパイル使用メモリ | 171,168 KB |
実行使用メモリ | 99,148 KB |
最終ジャッジ日時 | 2023-10-17 04:26:36 |
合計ジャッジ時間 | 10,014 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
34,888 KB |
testcase_01 | AC | 9 ms
34,888 KB |
testcase_02 | WA | - |
testcase_03 | AC | 420 ms
43,372 KB |
testcase_04 | AC | 436 ms
45,396 KB |
testcase_05 | AC | 871 ms
53,092 KB |
testcase_06 | AC | 269 ms
41,728 KB |
testcase_07 | AC | 68 ms
36,532 KB |
testcase_08 | AC | 98 ms
37,404 KB |
testcase_09 | AC | 46 ms
35,928 KB |
testcase_10 | AC | 136 ms
38,336 KB |
testcase_11 | AC | 516 ms
46,360 KB |
testcase_12 | AC | 302 ms
41,800 KB |
testcase_13 | AC | 142 ms
38,432 KB |
testcase_14 | AC | 35 ms
35,668 KB |
testcase_15 | AC | 215 ms
40,276 KB |
testcase_16 | AC | 588 ms
47,772 KB |
testcase_17 | AC | 654 ms
48,336 KB |
testcase_18 | AC | 133 ms
38,308 KB |
testcase_19 | AC | 549 ms
46,640 KB |
testcase_20 | AC | 52 ms
36,144 KB |
testcase_21 | AC | 89 ms
37,164 KB |
testcase_22 | AC | 422 ms
44,484 KB |
testcase_23 | AC | 238 ms
40,640 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 vector<int> tree[1000010]; int rtree[1000010]; int dfs(int i, int j){ int ans = (j*(j+1))/2; for(auto e : tree[i]){ ans += dfs(e, j+1); } 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; }