結果
問題 | No.1103 Directed Length Sum |
ユーザー | coco18000 |
提出日時 | 2020-07-03 22:08:14 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 676 ms / 3,000 ms |
コード長 | 1,105 bytes |
コンパイル時間 | 1,617 ms |
コンパイル使用メモリ | 171,288 KB |
実行使用メモリ | 107,764 KB |
最終ジャッジ日時 | 2023-10-17 03:40:34 |
合計ジャッジ時間 | 8,869 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
43,660 KB |
testcase_01 | AC | 16 ms
43,660 KB |
testcase_02 | AC | 294 ms
107,764 KB |
testcase_03 | AC | 179 ms
57,944 KB |
testcase_04 | AC | 382 ms
58,936 KB |
testcase_05 | AC | 676 ms
68,680 KB |
testcase_06 | AC | 237 ms
55,268 KB |
testcase_07 | AC | 53 ms
48,024 KB |
testcase_08 | AC | 78 ms
48,896 KB |
testcase_09 | AC | 38 ms
45,136 KB |
testcase_10 | AC | 114 ms
49,828 KB |
testcase_11 | AC | 411 ms
61,948 KB |
testcase_12 | AC | 242 ms
55,340 KB |
testcase_13 | AC | 113 ms
49,924 KB |
testcase_14 | AC | 32 ms
44,768 KB |
testcase_15 | AC | 181 ms
51,768 KB |
testcase_16 | AC | 466 ms
63,360 KB |
testcase_17 | AC | 486 ms
63,924 KB |
testcase_18 | AC | 113 ms
49,800 KB |
testcase_19 | AC | 430 ms
62,228 KB |
testcase_20 | AC | 43 ms
45,444 KB |
testcase_21 | AC | 69 ms
48,656 KB |
testcase_22 | AC | 343 ms
58,024 KB |
testcase_23 | AC | 197 ms
52,132 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll) 1e15; struct Vertex { vector<ll> children; ll parent = -1; ll depth = 0; }; Vertex V[1000005]; void dfs(ll node, ll depth = 0) { V[node].depth = depth; for (auto &n:V[node].children) { dfs(n, depth + 1); } } ll C[1000005]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; REP(i, N - 1) { ll a, b; cin >> a >> b; a--; b--; V[a].children.push_back(b); V[b].parent = a; } ll root = 0; REP(i, N) { if (V[i].parent < 0) { root = i; break; } } dfs(root); C[0] = 0; REP(i, N + 2) { C[i + 1] = (C[i] + i + 1) % MOD; } ll ans = 0; REP(i, N) { ans = (ans + C[V[i].depth]) % MOD; } cout << ans << endl; return 0; }