結果

問題 No.2427 Tree Distance Two
ユーザー Ping Chung ChangPing Chung Chang
提出日時 2023-08-28 20:21:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 168,348 KB
実行使用メモリ 40,512 KB
最終ジャッジ日時 2023-08-28 20:21:24
合計ジャッジ時間 12,720 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
17,536 KB
testcase_01 AC 6 ms
17,460 KB
testcase_02 AC 6 ms
17,396 KB
testcase_03 AC 310 ms
36,892 KB
testcase_04 AC 7 ms
17,640 KB
testcase_05 AC 289 ms
36,812 KB
testcase_06 AC 7 ms
17,636 KB
testcase_07 AC 192 ms
38,228 KB
testcase_08 AC 260 ms
40,512 KB
testcase_09 AC 264 ms
38,352 KB
testcase_10 AC 246 ms
39,132 KB
testcase_11 AC 217 ms
38,936 KB
testcase_12 AC 252 ms
37,652 KB
testcase_13 AC 285 ms
37,380 KB
testcase_14 AC 133 ms
36,152 KB
testcase_15 AC 7 ms
17,448 KB
testcase_16 AC 7 ms
17,448 KB
testcase_17 AC 6 ms
17,688 KB
testcase_18 AC 6 ms
17,444 KB
testcase_19 AC 6 ms
17,552 KB
testcase_20 AC 10 ms
17,960 KB
testcase_21 AC 11 ms
18,112 KB
testcase_22 AC 7 ms
17,560 KB
testcase_23 AC 6 ms
17,764 KB
testcase_24 AC 10 ms
17,920 KB
testcase_25 AC 54 ms
22,568 KB
testcase_26 AC 152 ms
29,444 KB
testcase_27 AC 98 ms
26,124 KB
testcase_28 AC 291 ms
35,400 KB
testcase_29 AC 217 ms
33,212 KB
testcase_30 AC 151 ms
29,296 KB
testcase_31 AC 87 ms
25,088 KB
testcase_32 AC 142 ms
28,992 KB
testcase_33 AC 126 ms
27,684 KB
testcase_34 AC 36 ms
20,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second

const int mxn = 3e5+10;
vector<int> tree[mxn];
vector<int> v[mxn];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i = 1;i<n;i++){
		int a,b;
		cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	for(int i = 1;i<=n;i++){
		for(auto &j:tree[i]){
			v[j].push_back(i);
		}
	}
	for(int i = 1;i<=n;i++){
		int sum = 0;
		for(auto &j:v[i])sum += tree[j].size()-1;
		cout<<sum<<'\n';
	}
	return 0;
}
0