結果

問題 No.806 木を道に
ユーザー addeight2addeight2
提出日時 2019-03-23 10:30:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 163,564 KB
実行使用メモリ 9,720 KB
最終ジャッジ日時 2023-10-22 00:11:25
合計ジャッジ時間 3,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,072 KB
testcase_01 AC 3 ms
6,072 KB
testcase_02 AC 3 ms
6,076 KB
testcase_03 AC 2 ms
6,076 KB
testcase_04 AC 3 ms
6,076 KB
testcase_05 AC 3 ms
6,080 KB
testcase_06 AC 3 ms
6,080 KB
testcase_07 AC 3 ms
6,076 KB
testcase_08 AC 3 ms
6,072 KB
testcase_09 AC 3 ms
6,076 KB
testcase_10 AC 9 ms
6,876 KB
testcase_11 AC 9 ms
6,792 KB
testcase_12 AC 34 ms
9,164 KB
testcase_13 AC 25 ms
8,320 KB
testcase_14 AC 33 ms
9,020 KB
testcase_15 AC 36 ms
9,208 KB
testcase_16 AC 13 ms
7,200 KB
testcase_17 AC 30 ms
8,784 KB
testcase_18 AC 5 ms
6,376 KB
testcase_19 AC 11 ms
6,920 KB
testcase_20 AC 30 ms
8,784 KB
testcase_21 AC 17 ms
7,604 KB
testcase_22 AC 44 ms
9,720 KB
testcase_23 AC 44 ms
9,720 KB
testcase_24 AC 16 ms
7,724 KB
testcase_25 AC 24 ms
8,576 KB
testcase_26 AC 10 ms
7,012 KB
testcase_27 AC 27 ms
9,380 KB
testcase_28 AC 4 ms
6,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll N;
const ll MAX_N=1e5;
vector<ll> G[MAX_N];
ll dst[MAX_N];
void dfs(ll v,ll p,ll d){
	dst[v]=d;
	for(auto e:G[v]){
		if(e!=p){
			dfs(e,v,d+1);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N-1){
		ll a,b;
		cin>>a>>b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll ans=0;
	REP(i,N){
		ans+=max((ll)G[i].size()-2,0ll);
	}
	cout<<ans<<endl;
}
0