結果

問題 No.2638 Initial fare
ユーザー ぷらぷら
提出日時 2024-02-19 21:27:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 141,224 KB
実行使用メモリ 16,612 KB
最終ジャッジ日時 2024-02-19 21:27:08
合計ジャッジ時間 4,229 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,676 KB
testcase_04 AC 81 ms
15,444 KB
testcase_05 AC 83 ms
16,068 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 77 ms
15,976 KB
testcase_08 AC 79 ms
15,556 KB
testcase_09 AC 73 ms
16,552 KB
testcase_10 AC 69 ms
16,596 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 79 ms
15,788 KB
testcase_13 AC 60 ms
14,892 KB
testcase_14 AC 74 ms
16,468 KB
testcase_15 AC 71 ms
16,612 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 73 ms
16,220 KB
testcase_18 AC 72 ms
15,908 KB
testcase_19 AC 78 ms
16,260 KB
testcase_20 AC 85 ms
16,112 KB
testcase_21 AC 109 ms
15,720 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 90 ms
15,540 KB
testcase_24 AC 87 ms
15,812 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 86 ms
15,940 KB
testcase_27 AC 85 ms
15,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<vector<int>>ki(N);
    vector<int>u(N-1),v(N-1);
    for(int i = 0; i < N-1; i++) {
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
        ki[u[i]].push_back(v[i]);
        ki[v[i]].push_back(u[i]);
    }
    long long ans = (N-1);
    for(int i = 0; i < N; i++) {
        ans += 1ll*ki[i].size()*(ki[i].size()-1)/2;
    }
    for(int i = 0; i < N-1; i++) {
        ans += 1ll*(ki[u[i]].size()-1)*(ki[v[i]].size()-1);
    }
    cout << ans << "\n";
}
0