結果
| 問題 |
No.1103 Directed Length Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-03 22:08:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 642 ms / 3,000 ms |
| コード長 | 1,105 bytes |
| コンパイル時間 | 1,736 ms |
| コンパイル使用メモリ | 170,280 KB |
| 実行使用メモリ | 107,520 KB |
| 最終ジャッジ日時 | 2024-09-17 02:19:31 |
| 合計ジャッジ時間 | 9,078 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#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;
}