結果
問題 | No.2888 Mamehinata |
ユーザー |
|
提出日時 | 2024-09-20 05:32:06 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 239 ms / 2,000 ms |
コード長 | 929 bytes |
コンパイル時間 | 3,285 ms |
コンパイル使用メモリ | 254,132 KB |
実行使用メモリ | 16,856 KB |
最終ジャッジ日時 | 2024-09-20 05:32:19 |
合計ジャッジ時間 | 12,395 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;using ll = long long;int main() {ll n, m;cin >> n >> m;vector<vector<int>> to(n);rep(i, m) {int a, b;cin >> a >> b;--a; --b;to[a].push_back(b);to[b].push_back(a);}if (!to[0].size()) {rep(i, n) puts("0");return 0;}const int INF = 1001001001;vector<int> dist(n, INF);queue<int> q;dist[0] = 0; q.push(0);while (q.size()) {int v = q.front(); q.pop();for (int u : to[v]) {if (dist[u] != INF) continue;dist[u] = dist[v]+1;q.push(u);}}vector<int> ans(n+1);for (int x : dist) if (x <= n) ans[x]++;rep(i, n-1) ans[i+2] += ans[i];for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';return 0;}