結果
問題 | No.1103 Directed Length Sum |
ユーザー | merom686 |
提出日時 | 2020-07-04 00:47:24 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 301 ms / 3,000 ms |
コード長 | 1,090 bytes |
コンパイル時間 | 843 ms |
コンパイル使用メモリ | 91,428 KB |
実行使用メモリ | 43,648 KB |
最終ジャッジ日時 | 2023-10-17 06:45:37 |
合計ジャッジ時間 | 5,121 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 215 ms
43,648 KB |
testcase_03 | AC | 161 ms
22,792 KB |
testcase_04 | AC | 160 ms
14,352 KB |
testcase_05 | AC | 301 ms
22,264 KB |
testcase_06 | AC | 98 ms
10,264 KB |
testcase_07 | AC | 21 ms
5,052 KB |
testcase_08 | AC | 32 ms
5,844 KB |
testcase_09 | AC | 13 ms
4,348 KB |
testcase_10 | AC | 46 ms
6,832 KB |
testcase_11 | AC | 173 ms
15,340 KB |
testcase_12 | AC | 99 ms
10,528 KB |
testcase_13 | AC | 47 ms
6,832 KB |
testcase_14 | AC | 11 ms
4,348 KB |
testcase_15 | AC | 74 ms
8,876 KB |
testcase_16 | AC | 212 ms
16,660 KB |
testcase_17 | AC | 219 ms
17,384 KB |
testcase_18 | AC | 46 ms
6,832 KB |
testcase_19 | AC | 182 ms
15,604 KB |
testcase_20 | AC | 16 ms
4,524 KB |
testcase_21 | AC | 29 ms
5,580 KB |
testcase_22 | AC | 139 ms
13,296 KB |
testcase_23 | AC | 81 ms
9,148 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; ll ans = 0; struct Graph { struct Vertex { int n; }; struct Edge { int i, n; }; Graph(int n, int m) : v(n, { -1 }), e(m), n(n), m(0) {} void add_edge(int i, int j) { e[m] = { j, v[i].n }; v[i].n = m; m++; } void dfs(int i, int d) { for (int j = v[i].n; j >= 0; j = e[j].n) { Edge& o = e[j]; dfs(o.i, d + 1); } ans += (ll)d * (d + 1) / 2; } vector<Vertex> v; vector<Edge> e; int n, m; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; Graph g(n, (n - 1) * 2); int x = 0; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; g.add_edge(a, b); x ^= b; } for (int i = n & ~3; i < n; i++) { x ^= i; } g.dfs(x, 0); cout << ans % 1000000007 << endl; return 0; }