結果

問題 No.2638 Initial fare
ユーザー kenken714kenken714
提出日時 2024-02-19 21:25:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 941 bytes
コンパイル時間 1,164 ms
コンパイル使用メモリ 163,232 KB
実行使用メモリ 21,236 KB
最終ジャッジ日時 2024-02-19 21:25:32
合計ジャッジ時間 5,262 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,536 KB
testcase_01 AC 3 ms
9,536 KB
testcase_02 AC 3 ms
9,536 KB
testcase_03 AC 3 ms
9,536 KB
testcase_04 AC 142 ms
20,172 KB
testcase_05 AC 157 ms
20,532 KB
testcase_06 AC 4 ms
9,536 KB
testcase_07 AC 136 ms
20,032 KB
testcase_08 AC 122 ms
19,824 KB
testcase_09 AC 178 ms
20,596 KB
testcase_10 AC 152 ms
20,724 KB
testcase_11 AC 3 ms
9,536 KB
testcase_12 AC 138 ms
19,968 KB
testcase_13 AC 135 ms
19,384 KB
testcase_14 AC 137 ms
20,528 KB
testcase_15 AC 134 ms
20,612 KB
testcase_16 AC 3 ms
9,536 KB
testcase_17 AC 145 ms
20,976 KB
testcase_18 AC 126 ms
20,184 KB
testcase_19 AC 140 ms
21,236 KB
testcase_20 AC 138 ms
20,868 KB
testcase_21 AC 140 ms
20,588 KB
testcase_22 AC 2 ms
9,536 KB
testcase_23 AC 138 ms
19,092 KB
testcase_24 AC 146 ms
19,400 KB
testcase_25 AC 3 ms
9,536 KB
testcase_26 AC 172 ms
20,468 KB
testcase_27 AC 145 ms
19,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, in[210000];
vector<ll> g[210000];
P p[210000];
int main(){
    cin >> n;
    REP(i, n - 1){
        ll  a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
        p[i] = P(a, b);
        in[a]++;
        in[b]++;
    }
    ll ans = 0;
    //3
    REP(i, n - 1){
        ans += (in[p[i].first] - 1) * (in[p[i].second] - 1);
    } 
    // 2
    REP(i, n){
        ans += in[i] * (in[i] - 1) / 2;
    }
    // 1
    ans += n - 1;
    cout << ans << endl;
}
0