結果

問題 No.2638 Initial fare
ユーザー otoshigootoshigo
提出日時 2024-02-19 21:35:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 872 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 78,908 KB
実行使用メモリ 14,916 KB
最終ジャッジ日時 2024-02-19 21:35:15
合計ジャッジ時間 3,149 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 72 ms
13,780 KB
testcase_05 AC 80 ms
14,404 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 69 ms
14,312 KB
testcase_08 AC 55 ms
13,996 KB
testcase_09 AC 60 ms
14,872 KB
testcase_10 AC 57 ms
14,900 KB
testcase_11 AC 1 ms
6,548 KB
testcase_12 AC 64 ms
14,252 KB
testcase_13 AC 49 ms
13,404 KB
testcase_14 AC 57 ms
14,796 KB
testcase_15 AC 56 ms
14,916 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 60 ms
14,556 KB
testcase_18 AC 62 ms
14,244 KB
testcase_19 AC 68 ms
14,596 KB
testcase_20 AC 75 ms
14,576 KB
testcase_21 AC 69 ms
14,184 KB
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 70 ms
13,876 KB
testcase_24 AC 72 ms
14,148 KB
testcase_25 AC 1 ms
6,548 KB
testcase_26 AC 87 ms
14,276 KB
testcase_27 AC 73 ms
14,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    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++){
        int l=G[i].size();
        ans+=l;
        ans+=(ll)2*l*(l-1)/2;
        for(auto x:G[i]){
            int m=G[x].size();
            ans+=(ll)(m-1)*(l-1);
        }
    }
    ans/=2;
    cout<<ans<<"\n";
}
0