For problem statement at 0-999/800-899/890-899/894/problemE.txt this is a correct solution, but verifier at 0-999/800-899/890-899/894/verifierE.go ends with case 3 failed: expected 79 got 171
input:2 7
1 2 5
2 2 16
1 2 0
2 2 9
1 1 14
1 1 5
1 1 7
1
exit status 1 can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"math"
"os"
)
var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
sc.Scan()
b := sc.Bytes()
x := 0
for _, c := range b {
x = x*10 + int(c-'0')
}
return x
}
type Edge struct {
to, w int
}
var (
adj [][]Edge
ids []int
low []int
onStack []bool
stack []int
sccID []int
sccWeight []int64
dagAdj [][]Edge
memo []int64
idCounter int
sccCount int
n, m int
)
func calc(w int) int64 {
if w == 0 {
return 0
}
wf := int64(w)
d := 1 + 8*wf
k := int64((1.0 + math.Sqrt(float64(d))) / 2.0)
if k*(k-1)/2 > wf {
k--
}
return k*wf - (k*(k*k-1))/6
}
func dfs(at int) {
stack = append(stack, at)
onStack[at] = true
ids[at] = idCounter
low[at] = idCounter
idCounter++
for _, e := range adj[at] {
to := e.to
if ids[to] == -1 {
dfs(to)
if low[to] < low[at] {
low[at] = low[to]
}
} else if onStack[to] {
if ids[to] < low[at] {
low[at] = ids[to]
}
}
}
if ids[at] == low[at] {
for {
node := stack[len(stack)-1]
stack = stack[:len(stack)-1]
onStack[node] = false
sccID[node] = sccCount
if node == at {
break
}
}
sccCount++
}
}
func solve(u int) int64 {
if memo[u] != -1 {
return memo[u]
}
var maxNext int64 = 0
for _, e := range dagAdj[u] {
val := int64(e.w) + solve(e.to)
if val > maxNext {
maxNext = val
}
}
memo[u] = sccWeight[u] + maxNext
return memo[u]
}
func main() {
const maxCap = 20 * 1024 * 1024
buf := make([]byte, maxCap)
sc.Buffer(buf, maxCap)
sc.Split(bufio.ScanWords)
if !sc.Scan() {
return
}
n = 0
for _, c := range sc.Bytes() {
n = n*10 + int(c-'0')
}
m = nextInt()
adj = make([][]Edge, n+1)
for i := 0; i < m; i++ {
u := nextInt()
v := nextInt()
w := nextInt()
adj[u] = append(adj[u], Edge{v, w})
}
s := nextInt()
ids = make([]int, n+1)
low = make([]int, n+1)
for i := range ids {
ids[i] = -1
}
onStack = make([]bool, n+1)
sccID = make([]int, n+1)
for i := 1; i <= n; i++ {
if ids[i] == -1 {
dfs(i)
}
}
sccWeight = make([]int64, sccCount)
dagAdj = make([][]Edge, sccCount)
memo = make([]int64, sccCount)
for i := range memo {
memo[i] = -1
}
for u := 1; u <= n; u++ {
uSCC := sccID[u]
for _, e := range adj[u] {
vSCC := sccID[e.to]
if uSCC == vSCC {
sccWeight[uSCC] += calc(e.w)
} else {
dagAdj[uSCC] = append(dagAdj[uSCC], Edge{vSCC, e.w})
}
}
}
fmt.Println(solve(sccID[s]))
}
```