結果

問題 No.2638 Initial fare
ユーザー daiotadaiota
提出日時 2024-02-19 22:19:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 683 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 178,796 KB
実行使用メモリ 40,176 KB
最終ジャッジ日時 2024-02-19 22:19:48
合計ジャッジ時間 7,824 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,692 KB
testcase_01 AC 4 ms
10,696 KB
testcase_02 AC 4 ms
10,692 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)

vector<ll> G[200010];
ll dep[200010];
ll p[200010];

void dfs(ll v,ll b,ll d){
	p[v]=b;
	dep[v]=d;
	for(ll i=0;i<(ll)G[v].size();i++) if(G[v][i]!=b) dfs(G[v][i],v,d+1);

}

int main(){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
   ll i,j;

	ll N;
	cin >> N;

	for(i=1;i<N;i++){
		ll a,b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	dfs(1,-1,0);

	map<ll,ll> m;
	for(i=1;i<=N;i++){
		m[dep[i]]++;
	}

	ll ans=0;
	for(i=0;i<N;i++){
		ans+=m[i]*(m[i+1]+m[i+2]+m[i+3]);
	}


	cout << ans << endl;






	return 0;

}
0