結果
問題 | No.2888 Mamehinata |
ユーザー |
![]() |
提出日時 | 2024-09-13 21:33:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 939 bytes |
コンパイル時間 | 2,355 ms |
コンパイル使用メモリ | 199,916 KB |
最終ジャッジ日時 | 2025-02-24 07:13:42 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define pb emplace_back #define mp make_pair using ll = long long; using pii = pair<int,int>; constexpr int mod = 998244353; constexpr int inf = 0x3f3f3f3f; constexpr int N = 2e5 + 10; int n, m, dep[N], cnt[N]; vector<int> V[N]; void _main(){ int x, y; cin >> n >> m; while(m--){ cin >> x >> y; V[x].pb(y); V[y].pb(x); } if(V[1].empty()){ for(int i=1; i<=n; ++i) cout << "0\n"; return; } memset(dep, -1, sizeof(dep)); dep[1] = 0; queue<int> Q; Q.push(1); while(!Q.empty()){ int x = Q.front(); Q.pop(); ++cnt[dep[x]]; for(int y : V[x]){ if(dep[y] == -1){ dep[y] = dep[x] + 1; Q.push(y); } } } int c0 = 0, c1 = 1; for(int i=1; i<=n; ++i){ swap(c0, c1); c1 += cnt[i]; cout << c1 << '\n'; } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); _main(); return 0; }