結果

問題 No.2888 Mamehinata
ユーザー hourenhouren
提出日時 2024-09-13 21:35:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,288 bytes
コンパイル時間 4,907 ms
コンパイル使用メモリ 281,752 KB
実行使用メモリ 16,860 KB
最終ジャッジ日時 2024-09-13 21:35:53
合計ジャッジ時間 9,444 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i,m){
        int u,v;
        cin >> u >> v;
        --u, --v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    if(!g[0].size()){
        rep(i,n) cout << "0\n";
        return 0;
    }
    vector<int> dist(n,INF), cnt(n+1,0);
    dist[0] = 0;
    queue<int> que;
    que.emplace(0);
    while(que.size()){
        int now = que.front();
        que.pop();
        for(int x:g[now]){
            if(chmin(dist[x], dist[now]+1)) que.emplace(x);
        }
    }
    rep(i,n) if(dist[i]<n) cnt[dist[i]] += 1;
    int ans[] = {1,0};
    for(int i=1;i<=n;++i){
        ans[i&1] += cnt[i];
        cout << ans[i&1] << '\n';
    }
    return 0;
}
0