結果

問題 No.2638 Initial fare
ユーザー cho435cho435
提出日時 2024-02-20 23:51:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 4,757 ms
コンパイル使用メモリ 263,288 KB
実行使用メモリ 15,020 KB
最終ジャッジ日時 2024-02-20 23:51:17
合計ジャッジ時間 9,028 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 166 ms
13,884 KB
testcase_05 AC 175 ms
14,508 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 158 ms
14,416 KB
testcase_08 AC 139 ms
14,100 KB
testcase_09 AC 147 ms
14,976 KB
testcase_10 AC 148 ms
15,004 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 169 ms
14,356 KB
testcase_13 AC 128 ms
13,508 KB
testcase_14 AC 153 ms
14,900 KB
testcase_15 AC 150 ms
15,020 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 154 ms
14,660 KB
testcase_18 AC 146 ms
14,348 KB
testcase_19 AC 161 ms
14,700 KB
testcase_20 AC 186 ms
14,680 KB
testcase_21 AC 159 ms
14,288 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 167 ms
13,980 KB
testcase_24 AC 175 ms
14,252 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 174 ms
14,380 KB
testcase_27 AC 191 ms
14,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

int main(){
	int n;
	cin>>n;
	vector<vector<int>> g(n);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u--; v--;
		g.at(u).push_back(v);
		g.at(v).push_back(u);
	}
	ll ans=0;
	ans+=n-1;
	rep(i,n){
		ans+=(ll)g.at(i).size()*(g.at(i).size()-1)/2;
	}
	ll tmp=0;
	rep(i,n){
		for(int j:g.at(i)){
			tmp+=(g.at(j).size()-1)*(g.at(i).size()-1);
		}
	}
	tmp/=2;
	ans+=tmp;
	cout<<ans<<endl;
}
0