結果

問題 No.2638 Initial fare
ユーザー てんぷらてんぷら
提出日時 2024-02-19 21:26:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 4,771 ms
コンパイル使用メモリ 310,712 KB
実行使用メモリ 21,684 KB
最終ジャッジ日時 2024-02-19 21:26:51
合計ジャッジ時間 7,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 72 ms
13,908 KB
testcase_05 AC 76 ms
14,532 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 64 ms
14,440 KB
testcase_08 AC 53 ms
14,124 KB
testcase_09 AC 57 ms
15,000 KB
testcase_10 AC 60 ms
15,028 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 68 ms
14,380 KB
testcase_13 AC 50 ms
13,532 KB
testcase_14 AC 58 ms
14,924 KB
testcase_15 AC 77 ms
15,044 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 60 ms
14,812 KB
testcase_18 AC 58 ms
14,372 KB
testcase_19 AC 77 ms
15,620 KB
testcase_20 AC 73 ms
15,088 KB
testcase_21 AC 70 ms
15,720 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 86 ms
21,684 KB
testcase_24 AC 86 ms
20,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 91 ms
18,500 KB
testcase_27 AC 84 ms
20,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    rep(i, n - 1) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    ll ans = 0;
    auto dfs = [&](auto &&self, int x, int p) -> tuple<int, int, int> {
        int v0 = 1, v1 = 0, v2 = 0;
        for(auto to : g[x]) {
            if(to == p)
                continue;
            auto [d1, d2, d3] = self(self, to, x);
            ans += (ll)v0 * d1;
            ans += (ll)v0 * d2;
            ans += (ll)v0 * d3;
            ans += (ll)v1 * d1;
            ans += (ll)v1 * d2;
            ans += (ll)v2 * d1;
            v1 += d1;
            v2 += d2;
        }
        return {v0, v1, v2};
    };
    dfs(dfs, 0, -1);
    cout << ans << endl;
    return 0;
}
0