結果
| 問題 |
No.2888 Mamehinata
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-09-15 14:48:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 123 ms / 2,000 ms |
| コード長 | 949 bytes |
| コンパイル時間 | 470 ms |
| コンパイル使用メモリ | 62,952 KB |
| 最終ジャッジ日時 | 2025-02-24 08:43:34 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:36:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
36 | scanf("%d%d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2888.cc: No.2888 Mamehinata - yukicoder
*/
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
using vi = vector<int>;
using qi = queue<int>;
/* global variables */
vi nbrs[MAX_N];
int ds[MAX_N], cs[MAX_N + 1];
/* subroutines */
/* main */
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
u--, v--;
nbrs[u].push_back(v);
nbrs[v].push_back(u);
}
fill(ds, ds + n, -1);
ds[0] = 0;
qi q;
q.push(0);
while (! q.empty()) {
int u = q.front(); q.pop();
cs[ds[u]]++;
for (auto v: nbrs[u])
if (ds[v] < 0)
ds[v] = ds[u] + 1, q.push(v);
}
int ss[2] = {(cs[1] > 0) ? 1 : 0, 0};
for (int i = 1; i <= n; i++) {
int p = (i & 1);
ss[p] += cs[i];
printf("%d\n", ss[p]);
}
return 0;
}
tnakao0123