結果

問題 No.2638 Initial fare
ユーザー matcharate12matcharate12
提出日時 2024-02-26 19:54:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 172,128 KB
実行使用メモリ 16,588 KB
最終ジャッジ日時 2024-02-26 19:54:44
合計ジャッジ時間 6,208 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 190 ms
15,420 KB
testcase_05 AC 176 ms
16,044 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 158 ms
15,952 KB
testcase_08 AC 146 ms
15,532 KB
testcase_09 AC 149 ms
16,528 KB
testcase_10 AC 154 ms
16,572 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 162 ms
15,764 KB
testcase_13 AC 136 ms
14,868 KB
testcase_14 AC 153 ms
16,444 KB
testcase_15 AC 153 ms
16,588 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 157 ms
16,196 KB
testcase_18 AC 141 ms
15,884 KB
testcase_19 AC 164 ms
16,236 KB
testcase_20 AC 163 ms
16,088 KB
testcase_21 AC 188 ms
15,696 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 166 ms
15,516 KB
testcase_24 AC 177 ms
15,788 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 176 ms
15,916 KB
testcase_27 AC 175 ms
15,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < n; i++) //[0,n)
#define srep(i,a,b) for(ll i = a; i < b; i++) //[a,b)
#define all(A) (A).begin(),(A).end()
#define rall(A) (A).rbegin(),(A).rend()
#define pmt(A) next_permutation(all(A))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
using pq = priority_queue<P,vector<P>,greater<P>>;
const ll inf = 1LL<<60;
const int iinf = (int)1e9+1;
const int mod9 = 998244353;
const int mod1 = 1000000007;
struct Edge { int to; long long cost; int from; };
bool compe(const Edge &e,const Edge &e2){ return e.cost < e2.cost; }
using Graph = vector<vector<int>>;
using SGraph = vector<set<ll>>;
template <class T>
int siz(T& a){return (int)a.size();}
ll squa(ll a){ return a*a; }
ll mceil(ll a,ll b){ return (a+b-1)/b; }

ll nC2(ll n){ return n*(n-1)/2; }

int main(void){
    int N; cin >> N;
    Graph G(N);
    vector<int> U(N),V(N);
    rep(i,N-1){
        int u,v; cin >> u >> v;
        u--; v--;
        U[i] = u,V[i] = v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    ll ans = N-1;
    rep(i,N) ans += nC2(siz(G[i]));
    rep(i,N-1) ans += 1LL*(siz(G[U[i]])-1)*(siz(G[V[i]])-1);
    cout << ans;
}
0