Submission #24524015
Source Code Expand
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
in := bufio.NewReader(os.Stdin)
var n, m int
fmt.Scan(&n, &m)
path := make([][]int, n)
var a, b int
for i := 0; i < m; i++ {
fmt.Fscan(in, &a, &b)
a--
b--
path[a] = append(path[a], b)
path[b] = append(path[b], a)
}
cost := make([]int, n)
for i := 0; i < n; i++ {
cost[i] = 200001
}
cost[0] = 0
to := make([]int, n)
to[0] = 1
q := make([]int, 0)
q = append(q, 0)
for len(q) > 0 {
v := q[0]
q = q[1:]
for _, u := range path[v] {
if cost[u] > cost[v]+1 {
cost[u] = cost[v] + 1
to[u] = to[v]
q = append(q, u)
} else if cost[u] == cost[v]+1 {
to[u] = to[u] + to[v]
to[u] %= 1000000007
}
}
}
fmt.Println(to[n-1])
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Number of Shortest paths |
| User | solareenlo |
| Language | Go (1.14.1) |
| Score | 400 |
| Code Size | 792 Byte |
| Status | AC |
| Exec Time | 266 ms |
| Memory | 23128 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
| All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| random_01.txt | AC | 249 ms | 22564 KiB |
| random_02.txt | AC | 227 ms | 19040 KiB |
| random_03.txt | AC | 148 ms | 17260 KiB |
| random_04.txt | AC | 131 ms | 10672 KiB |
| random_05.txt | AC | 266 ms | 22848 KiB |
| random_06.txt | AC | 221 ms | 17568 KiB |
| random_07.txt | AC | 66 ms | 12112 KiB |
| random_08.txt | AC | 44 ms | 5988 KiB |
| random_09.txt | AC | 256 ms | 23128 KiB |
| random_10.txt | AC | 236 ms | 17576 KiB |
| random_11.txt | AC | 75 ms | 12260 KiB |
| random_12.txt | AC | 25 ms | 5716 KiB |
| random_13.txt | AC | 264 ms | 23088 KiB |
| random_14.txt | AC | 266 ms | 22364 KiB |
| random_15.txt | AC | 217 ms | 20320 KiB |
| random_16.txt | AC | 118 ms | 12280 KiB |
| random_17.txt | AC | 257 ms | 22824 KiB |
| random_18.txt | AC | 215 ms | 15572 KiB |
| random_19.txt | AC | 230 ms | 21364 KiB |
| random_20.txt | AC | 89 ms | 9848 KiB |
| random_31.txt | AC | 154 ms | 9636 KiB |
| random_32.txt | AC | 196 ms | 18464 KiB |
| random_33.txt | AC | 258 ms | 17544 KiB |
| random_34.txt | AC | 227 ms | 13128 KiB |
| random_35.txt | AC | 230 ms | 13164 KiB |
| random_36.txt | AC | 249 ms | 16468 KiB |
| sample_01.txt | AC | 1 ms | 1820 KiB |
| sample_02.txt | AC | 2 ms | 1824 KiB |
| sample_03.txt | AC | 1 ms | 1820 KiB |
| sample_04.txt | AC | 2 ms | 1832 KiB |