結果

問題 No.2888 Mamehinata
ユーザー tottoripapertottoripaper
提出日時 2024-09-13 22:03:50
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,113 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 208,628 KB
実行使用メモリ 16,756 KB
最終ジャッジ日時 2024-09-13 22:04:12
合計ジャッジ時間 13,787 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int N, M;
    std::cin >> N >> M;

    std::vector<std::vector<int>> G(N + 1);
    for(int i=0;i<M;i++){
        int u, v;
        std::cin >> u >> v;

        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    std::queue<int> queue;
    std::vector<int> dist(N + 1, -1);
    queue.emplace(1);
    dist[1] = 0;
    
    while(!queue.empty()){
        int v = queue.front();
        queue.pop();

        for(int w : G[v]){
            if(dist[w] == -1){
                queue.emplace(w);
                dist[w] = dist[v] + 1;
            }
        }
    }

    std::vector<int> count(N + 1, 0);
    for(int i=1;i<=N;i++){
        if(dist[i] != -1){
            count[dist[i]] += 1;
        }
    }

    int count_even = 1, count_odd = 0;
    for(int i=1;i<=N;i++){
        if(i % 2 == 1){
            count_odd += count[i];
            std::cout << count_odd << std::endl;
        }else{
            count_even += count[i];
            std::cout << count_even << std::endl;
        }
    }
}
0