結果
問題 | No.2888 Mamehinata |
ユーザー |
![]() |
提出日時 | 2024-09-14 15:30:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 143 ms / 2,000 ms |
コード長 | 880 bytes |
コンパイル時間 | 1,693 ms |
コンパイル使用メモリ | 201,508 KB |
最終ジャッジ日時 | 2025-02-24 08:34:42 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}int main() {fast_io();int n, m;cin >> n >> m;vector<vector<int>> g(n);for (int i = 0; i < m; i++) {int u, v;cin >> u >> v;u--, v--;g[u].push_back(v);g[v].push_back(u);}if (g[0].empty()) {for (int i = 0; i < n; i++) {cout << "0\n";}return 0;}vector<int> dist(n, -1);dist[0] = 0;deque<int> dq;dq.push_back(0);while (!dq.empty()) {int u = dq.front();dq.pop_front();for (int v : g[u]) {if (dist[v] == -1) {dist[v] = dist[u] + 1;dq.push_back(v);}}}vector<int> ans(n + 1, 0);for (int i = 0; i < n; i++) {if (dist[i] != -1) {ans[dist[i]]++;}}for (int i = 2; i <= n; i++) {ans[i] += ans[i - 2];}for (int i = 1; i <= n; i++) {cout << ans[i] << "\n";}}