結果

問題 No.2638 Initial fare
ユーザー throughthrough
提出日時 2024-02-19 21:45:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 3,684 ms
コンパイル使用メモリ 235,004 KB
実行使用メモリ 24,628 KB
最終ジャッジ日時 2024-02-19 21:46:04
合計ジャッジ時間 5,908 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 75 ms
14,932 KB
testcase_05 AC 79 ms
15,556 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 69 ms
15,172 KB
testcase_08 AC 56 ms
14,764 KB
testcase_09 AC 59 ms
15,768 KB
testcase_10 AC 55 ms
15,924 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 66 ms
15,068 KB
testcase_13 AC 47 ms
14,172 KB
testcase_14 AC 56 ms
15,692 KB
testcase_15 AC 53 ms
15,812 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 65 ms
15,836 KB
testcase_18 AC 55 ms
15,140 KB
testcase_19 AC 77 ms
17,284 KB
testcase_20 AC 72 ms
16,240 KB
testcase_21 AC 74 ms
17,384 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 89 ms
24,628 KB
testcase_24 AC 111 ms
23,108 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 87 ms
21,188 KB
testcase_27 AC 88 ms
23,356 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:30:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   30 |             auto [t1, t2, t3, t4] = self(self, to, now);
      |                  ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll, ll>;
#include <atcoder/all>
using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define reps(i, l, r) for(ll i = l; i < r; i++)

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    ll n; cin >> n;
    vector<vector<ll>> Graph(n);
    rep(i,n-1) {
        ll u, v; cin >> u >> v; u--; v--;
        Graph[u].push_back(v);
        Graph[v].push_back(u);
    }
    ll ans = 0;
    auto dfs = [&](auto self, ll now, ll pre) -> T {
        bool f = false;
        ll n1 = 1, n2 = 0, n3 = 0, n4 = 0;
        for(auto to: Graph[now]) {
            if(to == pre) continue;
            auto [t1, t2, t3, t4] = self(self, to, now);
            ans += n2*t1 + n3*t1 + n2*t2;
            n2 += t1, n3 += t2, n4 += t3;
        }
        ans += n2 + n3 + n4;
        return T(n1, n2, n3, n4);
    };
    T t = dfs(dfs, 0, -1);
    cout << ans << endl;
    
    return 0;
}
0