結果
| 問題 |
No.2427 Tree Distance Two
|
| コンテスト | |
| ユーザー |
hatsuka_iwa
|
| 提出日時 | 2023-09-04 19:00:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 763 ms / 2,000 ms |
| コード長 | 562 bytes |
| コンパイル時間 | 2,253 ms |
| コンパイル使用メモリ | 199,676 KB |
| 最終ジャッジ日時 | 2025-02-16 18:36:25 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
#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;
}
hatsuka_iwa