結果

問題 No.2638 Initial fare
ユーザー RubikunRubikun
提出日時 2024-02-19 22:47:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 948 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 206,512 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-02-19 22:47:24
合計ジャッジ時間 4,765 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 51 ms
7,808 KB
testcase_05 AC 50 ms
8,064 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 48 ms
7,936 KB
testcase_08 AC 45 ms
7,680 KB
testcase_09 AC 48 ms
8,064 KB
testcase_10 AC 49 ms
8,064 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 50 ms
7,936 KB
testcase_13 AC 44 ms
7,476 KB
testcase_14 AC 52 ms
7,936 KB
testcase_15 AC 51 ms
8,064 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 49 ms
7,808 KB
testcase_18 AC 48 ms
7,808 KB
testcase_19 AC 50 ms
7,808 KB
testcase_20 AC 49 ms
7,808 KB
testcase_21 AC 49 ms
7,808 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 48 ms
7,936 KB
testcase_24 AC 52 ms
8,064 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 51 ms
8,064 KB
testcase_27 AC 49 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<ll> deg(N);
    vector<pair<ll,ll>> E(N-1);
    
    for(int i=0;i<N-1;i++){
        ll a,b;cin>>a>>b;a--;b--;
        E[i]=mp(a,b);
        deg[a]++;
        deg[b]++;
    }
    
    ll ans=0;
    
    for(auto [a,b]:E){
        ans+=deg[a]*deg[b];
    }
    
    for(int i=0;i<N;i++){
        ans-=deg[i]*(deg[i]-1)/2;
    }
    
    cout<<ans<<endl;
}

0