結果

問題 No.2638 Initial fare
ユーザー Today03Today03
提出日時 2024-02-19 21:43:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 953 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 215,552 KB
実行使用メモリ 29,668 KB
最終ジャッジ日時 2024-02-19 21:43:09
合計ジャッジ時間 8,160 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 533 ms
14,012 KB
testcase_05 AC 541 ms
14,508 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        queue<pair<int, int>> Q;
        set<int> S;
        Q.push(make_pair(i, 0));
        S.insert(i);
        while (!Q.empty()) {
            auto [now, d] = Q.front();
            Q.pop();

            ans++;
            if (d == 3) continue;
            for (int nxt : G[now]) {
                if (!S.count(nxt)) {
                    Q.push(make_pair(nxt, d + 1));
                    S.insert(nxt);
                }
            }
        }
    }

    ans -= N;
    ans /= 2;
    cout << ans << endl;
}
0