結果

問題 No.2427 Tree Distance Two
ユーザー umezoumezo
提出日時 2023-08-22 14:58:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 619 bytes
コンパイル時間 2,717 ms
コンパイル使用メモリ 201,556 KB
実行使用メモリ 30,044 KB
最終ジャッジ日時 2023-08-22 14:58:42
合計ジャッジ時間 9,351 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,392 KB
testcase_01 AC 5 ms
10,632 KB
testcase_02 AC 5 ms
10,408 KB
testcase_03 AC 227 ms
20,808 KB
testcase_04 AC 5 ms
10,396 KB
testcase_05 AC 250 ms
20,800 KB
testcase_06 AC 5 ms
10,564 KB
testcase_07 AC 148 ms
21,840 KB
testcase_08 AC 208 ms
22,992 KB
testcase_09 AC 172 ms
21,924 KB
testcase_10 AC 190 ms
22,192 KB
testcase_11 AC 171 ms
21,636 KB
testcase_12 AC 176 ms
21,596 KB
testcase_13 AC 196 ms
21,348 KB
testcase_14 AC 109 ms
30,044 KB
testcase_15 AC 5 ms
10,520 KB
testcase_16 AC 5 ms
10,396 KB
testcase_17 AC 5 ms
10,400 KB
testcase_18 AC 5 ms
10,392 KB
testcase_19 AC 5 ms
10,636 KB
testcase_20 AC 7 ms
10,684 KB
testcase_21 AC 9 ms
10,760 KB
testcase_22 AC 6 ms
10,488 KB
testcase_23 AC 6 ms
10,628 KB
testcase_24 AC 7 ms
10,708 KB
testcase_25 AC 43 ms
12,948 KB
testcase_26 AC 108 ms
16,852 KB
testcase_27 AC 68 ms
15,044 KB
testcase_28 AC 181 ms
20,084 KB
testcase_29 AC 152 ms
18,940 KB
testcase_30 AC 99 ms
16,688 KB
testcase_31 AC 60 ms
14,284 KB
testcase_32 AC 99 ms
16,616 KB
testcase_33 AC 111 ms
15,824 KB
testcase_34 AC 28 ms
12,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

vector<int> G[300300];
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  vector<int> ANS(n);  
  auto dfs=[&](auto dfs,int v,int p)->void{
    for(auto nv:G[v]){
      ANS[nv]+=(int)G[v].size()-1;
      if(nv==p) continue;
      dfs(dfs,nv,v);
    }
  };
  
  dfs(dfs,0,-1);
  rep(i,n) cout<<ANS[i]<<'\n';
  
  return 0;
}
0