結果

問題 No.2427 Tree Distance Two
ユーザー hatsuka_iwahatsuka_iwa
提出日時 2023-09-04 19:00:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 750 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 4,432 ms
コンパイル使用メモリ 205,492 KB
実行使用メモリ 38,444 KB
最終ジャッジ日時 2023-09-04 19:00:41
合計ジャッジ時間 20,322 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 729 ms
21,024 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 750 ms
21,020 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 651 ms
21,904 KB
testcase_08 AC 703 ms
22,852 KB
testcase_09 AC 665 ms
21,892 KB
testcase_10 AC 674 ms
22,356 KB
testcase_11 AC 686 ms
22,336 KB
testcase_12 AC 677 ms
21,388 KB
testcase_13 AC 706 ms
21,100 KB
testcase_14 AC 634 ms
38,444 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 17 ms
4,380 KB
testcase_21 AC 20 ms
4,380 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 17 ms
4,380 KB
testcase_25 AC 170 ms
7,808 KB
testcase_26 AC 432 ms
14,056 KB
testcase_27 AC 332 ms
10,908 KB
testcase_28 AC 666 ms
19,588 KB
testcase_29 AC 614 ms
17,580 KB
testcase_30 AC 407 ms
13,764 KB
testcase_31 AC 262 ms
10,136 KB
testcase_32 AC 433 ms
13,760 KB
testcase_33 AC 363 ms
12,432 KB
testcase_34 AC 106 ms
5,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N; cin >> N;
  vector<int> Ans(N + 1);
  vector<vector<int>> Graph(N + 1);

  for (int i = 0; i < N - 1; i++) {
    int u, v; cin >> u >> v;
    Graph.at(u).push_back(v);
    Graph.at(v).push_back(u);
  }

  auto DFS = [&](auto DFS, int x, int p) -> void {
    for (int to : Graph.at(x)) {
      if (to == p) continue;
      Ans.at(p)++;
      Ans.at(to) += Graph.at(x).size() - 1;
      DFS(DFS, to, x);
    }
  };
  
  DFS(DFS, 1, 0);
  for (int i = 1; i <= N; i++) cout << Ans.at(i) << endl;
}
0