結果

問題 No.1103 Directed Length Sum
ユーザー 👑 hitonanodehitonanode
提出日時 2020-07-11 10:42:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 906 ms / 3,000 ms
コード長 940 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 200,336 KB
実行使用メモリ 145,536 KB
最終ジャッジ日時 2024-04-20 20:58:38
合計ジャッジ時間 10,185 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 403 ms
145,536 KB
testcase_03 AC 253 ms
85,252 KB
testcase_04 AC 464 ms
56,192 KB
testcase_05 AC 906 ms
94,976 KB
testcase_06 AC 256 ms
37,888 KB
testcase_07 AC 40 ms
11,520 KB
testcase_08 AC 63 ms
15,872 KB
testcase_09 AC 23 ms
8,448 KB
testcase_10 AC 112 ms
20,608 KB
testcase_11 AC 512 ms
61,184 KB
testcase_12 AC 266 ms
38,016 KB
testcase_13 AC 109 ms
21,120 KB
testcase_14 AC 18 ms
7,040 KB
testcase_15 AC 191 ms
30,464 KB
testcase_16 AC 590 ms
68,224 KB
testcase_17 AC 637 ms
71,040 KB
testcase_18 AC 99 ms
20,608 KB
testcase_19 AC 532 ms
62,592 KB
testcase_20 AC 27 ms
9,728 KB
testcase_21 AC 54 ms
14,720 KB
testcase_22 AC 408 ms
51,712 KB
testcase_23 AC 211 ms
32,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> to(N), from(N);
    REP(_, N - 1)
    {
        int a, b;
        cin >> a >> b;
        to[a - 1].emplace_back(b - 1), from[b - 1].emplace_back(a - 1);
    }
    int r = 0;
    while (from[r].size()) r++;

    lint ret = 0;
    auto dfs = [&](auto &&rec, int now, lint d) -> void {
        for (int nxt : to[now])
        {
            rec(rec, nxt, d + 1);
        }
        ret += d * (d + 1) / 2;
        ret %= 1000000007;
    };
    dfs(dfs, r, 0);
    cout << ret << '\n';
}
0