結果
| 問題 |
No.2888 Mamehinata
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-13 22:43:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 166 ms / 2,000 ms |
| コード長 | 1,126 bytes |
| コンパイル時間 | 2,261 ms |
| コンパイル使用メモリ | 202,960 KB |
| 最終ジャッジ日時 | 2025-02-24 08:01:44 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> BFS(vector<vector<int>> &Graph,int start){
int N = Graph.size();
vector<int> ret(N,-1);
queue<int> Q;
ret.at(start) = 0,Q.push(start);
while(Q.size()){
int pos = Q.front(); Q.pop();
for(auto to : Graph.at(pos)){
if(ret.at(to) != -1) continue;
ret.at(to) = ret.at(pos)+1;
Q.push(to);
}
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M; cin >> N >> M;
vector<vector<int>> Graph(N);
for(int i=0; i<M; i++){
int u,v; cin >> u >> v;
u--; v--;
Graph.at(u).push_back(v);
Graph.at(v).push_back(u);
}
vector<int> dist = BFS(Graph,0);
vector<int> rev(N+1);
for(auto &d : dist) if(d != -1) rev.at(d)++;
int one = 1,two = 0;
if(Graph.at(0).size() == 0){
for(int t=0; t<N; t++) cout << "0\n";
return 0;
}
for(int i=1; i<=N; i++){
if(i%2 == 0) one += rev.at(i),cout << one << "\n";
else two += rev.at(i),cout << two << "\n";
}
}