結果

問題 No.2638 Initial fare
ユーザー yuyu_5510yuyu_5510
提出日時 2024-02-19 22:39:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 173,420 KB
実行使用メモリ 16,684 KB
最終ジャッジ日時 2024-02-19 22:40:03
合計ジャッジ時間 5,492 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 146 ms
15,420 KB
testcase_05 AC 144 ms
16,044 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 157 ms
15,952 KB
testcase_08 AC 122 ms
15,508 KB
testcase_09 AC 126 ms
16,512 KB
testcase_10 AC 130 ms
16,668 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 140 ms
15,764 KB
testcase_13 AC 113 ms
14,916 KB
testcase_14 AC 134 ms
16,436 KB
testcase_15 AC 126 ms
16,684 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 136 ms
16,196 KB
testcase_18 AC 148 ms
15,884 KB
testcase_19 AC 142 ms
16,236 KB
testcase_20 AC 139 ms
16,088 KB
testcase_21 AC 142 ms
15,696 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 141 ms
15,516 KB
testcase_24 AC 150 ms
15,788 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 154 ms
15,916 KB
testcase_27 AC 154 ms
15,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
int main(){
    long long 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);
    }

    vector<long long> around(n);
    for(int i = 0;i < n;i++){
        for(auto to : g[i]){
            around[i] += g[to].size();
        }
    }

    long long ans = 0;
    for(int i = 0;i < n;i++){
        for(auto to : g[i]){
            ans += (long long) (g[i].size() - 1) * (g[to].size() - 1);
        }
    }
    ans /= 2;

    for(int i = 0;i < n;i++){
        ans += ((long long) g[i].size()) * (g[i].size() - 1) / 2;
    }

    long long add = 0;
    for(int i = 0;i < n;i++){
        add += (long long)g[i].size();
    }
    ans += add / 2;

    cout << ans << endl;
}
0