結果

問題 No.2638 Initial fare
ユーザー SlephySlephy
提出日時 2024-02-25 19:48:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 2,392 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 207,532 KB
実行使用メモリ 15,044 KB
最終ジャッジ日時 2024-02-25 19:48:19
合計ジャッジ時間 6,141 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 101 ms
13,908 KB
testcase_05 AC 99 ms
14,532 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 86 ms
14,440 KB
testcase_08 AC 69 ms
14,124 KB
testcase_09 AC 74 ms
15,000 KB
testcase_10 AC 75 ms
15,028 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 92 ms
14,380 KB
testcase_13 AC 67 ms
13,532 KB
testcase_14 AC 77 ms
14,924 KB
testcase_15 AC 99 ms
15,044 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 80 ms
14,684 KB
testcase_18 AC 75 ms
14,372 KB
testcase_19 AC 84 ms
14,724 KB
testcase_20 AC 97 ms
14,704 KB
testcase_21 AC 95 ms
14,312 KB
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 105 ms
14,004 KB
testcase_24 AC 107 ms
14,276 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 105 ms
14,404 KB
testcase_27 AC 108 ms
14,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e9 + 1001010;
const ll llINF = (long long)4e18 + 22000020;
const string endn = "\n";
template <class T> inline auto vector2(size_t i, size_t j, const T &init = T()) {return vector(i, vector<T>(j, init));}
const string ELEM_SEPARATION = " ", VEC_SEPARATION = endn;
template<class T> istream& operator >>(istream &i, vector<T> &A) {for(auto &I : A) {i >> I;} return i;}
template<class T> ostream& operator <<(ostream &o, const vector<T> &A) {int i=A.size(); for(auto &I : A){o << I << (--i ? ELEM_SEPARATION : "");} return o;}
template<class T> ostream& operator <<(ostream &o, const vector<vector<T>> &A) {int i=A.size(); for(auto &I : A){o << I << (--i ? VEC_SEPARATION : "");} return o;}
template<class T> vector<T>& operator ++(vector<T> &A, int n) {for(auto &I : A) {I++;} return A;}
template<class T> vector<T>& operator --(vector<T> &A, int n) {for(auto &I : A) {I--;} return A;}
template<class T, class U> bool chmax(T &a, const U &b) {return ((a < b) ? (a = b, true) : false);}
template<class T, class U> bool chmin(T &a, const U &b) {return ((a > b) ? (a = b, true) : false);}
ll floor(ll a, ll b){if (b < 0) a = -a, b = -b; if(a >= 0) return a / b; else return (a + 1) / b - 1;}
ll ceil(ll a, ll b){if (b < 0) a = -a, b = -b; if(a > 0) return (a - 1) / b + 1; else return a / b;}
ll bit(unsigned long long val, unsigned long long digit){return (val >> digit) & 1;}
#ifdef LOCAL
#include <debug_slephy.cpp>
#else
#define debug(...)
#endif
// ================================== ここまでテンプレ ==================================


int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n; cin >> n;
    auto graph = vector2<int>(n, 0);
    for(int i = 0; i < n-1; i++){
        int u, v; cin >> u >> v;
        u--; v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    ll ans = 0;
    // dist = 1
    ans += n-1;

    // dist = 2
    for(int i = 0; i < n; i++){
        ll sz = graph[i].size();
        ans += sz * (sz-1) / 2;
    }

    // dist = 3
    ll d3 = 0;
    for(int i = 0; i < n; i++){
        for(auto j : graph[i]){
            ll szi = graph[i].size();
            ll szj = graph[j].size();
            d3 += (szi-1) * (szj-1);
        }
    }
    ans += d3 / 2;

    cout << ans << endn;
    return 0;
}
0