結果

問題 No.2427 Tree Distance Two
ユーザー hatsuka_iwa
提出日時 2023-09-04 00:57:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 679 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 200,404 KB
最終ジャッジ日時 2025-02-16 18:30:35
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N; cin >> N;
  vector<bool> seen(N + 1);
  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 s, int x, int c) -> void {
    if (c == 0) {
      Ans.at(s)++;
      return;
    }
    seen.at(x) = true;
    for (int to : Graph.at(x)) {
      if (seen.at(to)) continue;
      DFS(DFS, s, to, c - 1);
    }
    seen.at(x) = false;
  };

  for (int i = 1; i <= N; i++) DFS(DFS, i, i, 2);
  for (int i = 1; i <= N; i++) cout << Ans.at(i) << endl;
}
0