結果
問題 | No.1103 Directed Length Sum |
ユーザー |
|
提出日時 | 2020-07-03 22:06:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,103 bytes |
コンパイル時間 | 1,535 ms |
コンパイル使用メモリ | 168,724 KB |
実行使用メモリ | 90,180 KB |
最終ジャッジ日時 | 2024-09-17 02:11:29 |
合計ジャッジ時間 | 17,986 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 2 |
other | RE * 22 |
コンパイルメッセージ
main.cpp: In function 'll dfs(ll, ll)': main.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type] 28 | } | ^
ソースコード
#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];ll 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;}