結果
問題 | No.2888 Mamehinata |
ユーザー |
![]() |
提出日時 | 2025-03-22 13:20:57 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 606 ms / 2,000 ms |
コード長 | 705 bytes |
コンパイル時間 | 13,714 ms |
コンパイル使用メモリ | 247,804 KB |
実行使用メモリ | 22,596 KB |
最終ジャッジ日時 | 2025-03-22 13:21:29 |
合計ジャッジ時間 | 30,837 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
package mainimport . "fmt"import . "os"import bf "bufio"func main() {rd:=bf.NewReader(Stdin)var n, m intFscan(rd,&n,&m)graph := make([][]int, n+1)for i:=0;i<m;i++ {var u,v intFscan(rd,&u,&v)graph[u]=append(graph[u],v)graph[v]=append(graph[v],u)}visited := make([]bool, n+1)visited[1] = truecnt1,cnt2 := 0,1if len(graph[1])==0 {cnt2=0}nodes, nexts := []int{1}, []int{}for i:=0; i< n; i++ {nexts = nexts[:0]for _, node := range nodes {for _, t := range graph[node] {if visited[t] {continue}cnt1++nexts = append(nexts, t)visited[t] = true}}Println(cnt1)cnt1,cnt2=cnt2,cnt1nodes, nexts = nexts, nodes}}