結果

問題 No.2638 Initial fare
ユーザー ramdosramdos
提出日時 2024-02-11 13:36:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 792 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 205,996 KB
実行使用メモリ 14,484 KB
最終ジャッジ日時 2024-02-11 14:07:52
合計ジャッジ時間 13,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
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 #

//N^2
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    ll N;
    cin >> N;
    vector<ll> v(N);
    vector<pair<ll,ll>> e(N-1);
    rep(i,N-1){
        cin >> e[i].first >> e[i].second;
        e[i].first--;
        e[i].second--;
        v[e[i].first]++;
        v[e[i].second]++;
    }
    ll ans = N-1; //distance=1
    rep(i,N){ //distance=2
        ans+=v[i]*(v[i]-1)/2;
    }
    rep(i,N-1){//distance=3
        ll s=-1;
        ll t=-1;
        rep(j,N-1){
            if(e[i].first==e[j].first) s++;
            if(e[i].first==e[j].second) s++;
            if(e[i].second==e[j].first) t++;
            if(e[i].second==e[j].second) t++;
        }
        ans+=s*t;
    }
    cout << ans << endl;
}
0