← Home
For problem statement at 0-999/800-899/850-859/855/problemD.txt this is a correct solution, but verifier at 0-999/800-899/850-859/855/verifierD.go ends with mismatch on test 4 query 47: expected NO got YES
input:
33
-1 -1
-1 -1
-1 -1
2 1
4 1
3 0
2 0
5 1
-1 -1
-1 -1
8 1
5 1
9 1
11 0
5 0
4 1
13 0
-1 -1
14 0
16 1
-1 -1
6 1
3 1
11 0
19 1
-1 -1
1 1
13 0
4 1
23 1
-1 -1
18 0
28 0
185
1 4 28
1 22 9
2 9 11
1 25 18
2 3 6
1 16 24
2 28 30
1 16 25
1 29 33
2 2 15
2 15 10
1 2 31
2 24 11
2 10 24
2 27 12
1 28 8
2 32 15
1 14 9
1 9 30
1 25 8
1 25 25
2 20 11
1 1 16
1 33 3
1 28 26
1 28 1
1 4 32
2 13 5
2 26 20
1 22 28
1 9 15
2 4 26
1 2 7
1 5 27
2 7 1
2 13 10
2 1 18
2 33 1
2 6 27
2 14 1
2 27 16
1 22 11
1 11 3
1 6 3
1 4 4
1 24 18
2 22 28
1 9 15
2 24 30
2 19 30
1 1 8
1 28 27
1 7 24
1 32 24
1 2 19
2 21 17
1 11 27
1 25 2
2 9 17
1 16 28
1 22 1
2 13 15
1 32 11
2 27 27
2 6 9
2 26 14
1 21 17
1 30 1
1 23 24
2 20 23
1 31 17
2 6 6
2 22 19
1 4 5
1 26 11
2 27 11
1 21 5
1 7 2
2 14 21
2 2 17
2 19 23
1 19 11
1 8 26
2 30 28
2 18 11
2 15 15
1 22 12
2 13 4
2 14 32
2 16 20
2 2 14
1 3 14
1 21 29
2 7 25
2 23 8
1 21 18
1 9 25
2 27 19
2 6 14
1 1 5
2 5 18
1 32 10
1 5 2
1 13 33
2 3 27
1 10 11
1 23 16
2 6 3
1 16 3
1 12 18
2 33 22
2 2 26
2 12 7
1 17 23
1 33 32
1 23 19
1 5 1
1 10 12
2 32 33
2 12 4
2 27 26
1 26 13
1 12 8
2 21 22
1 31 8
2 19 27
1 27 33
2 2 33
2 15 1
1 28 6
2 5 1
2 8 30
1 6 13
1 17 33
1 13 26
2 3 26
1 30 5
1 3 10
1 26 27
2 16 16
1 7 16
2 2 17
1 21 21
2 26 7
2 14 8
2 20 26
1 32 13
2 13 27
2 14 31
1 24 6
2 12 4
1 30 24
2 17 14
2 19 21
2 3 32
2 16 22
1 8 11
1 2 33
2 25 27
1 15 16
2 15 30
2 29 29
2 3 29
2 8 18
2 6 17
1 19 21
1 18 12
2 32 9
2 25 15
2 27 26
1 14 28
2 5 21
2 1 25
1 22 19
2 8 16
1 11 10
2 22 13
2 24 16
2 30 6
1 14 14
2 4 18
1 32 15
2 17 27
2 31 32
1 23 32

exit status 1 can you fix the verifier? package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(in, &n)
	parent := make([]int, n+1)
	typ := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &parent[i], &typ[i])
	}
	special_parent := make([]int, n+1)
	part_parent := make([]int, n+1)
	for i := 1; i <= n; i++ {
		if parent[i] != -1 {
			if typ[i] == 0 {
				special_parent[i] = parent[i]
			} else if typ[i] == 1 {
				part_parent[i] = parent[i]
			}
		} else {
			special_parent[i] = -1
			part_parent[i] = -1
		}
	}
	depth := make([]int, n+1)
	for i := 1; i <= n; i++ {
		if special_parent[i] == -1 {
			depth[i] = 0
		} else {
			depth[i] = 1 + depth[special_parent[i]]
		}
	}
	const LOG = 18
	par := make([][]int, LOG)
	for k := 0; k < LOG; k++ {
		par[k] = make([]int, n+1)
	}
	for i := 1; i <= n; i++ {
		par[0][i] = special_parent[i]
	}
	for k := 1; k < LOG; k++ {
		for i := 1; i <= n; i++ {
			mid := par[k-1][i]
			if mid != -1 {
				par[k][i] = par[k-1][mid]
			} else {
				par[k][i] = -1
			}
		}
	}
	attach := make([]int, n+1)
	for i := 1; i <= n; i++ {
		if part_parent[i] == -1 {
			attach[i] = i
		} else {
			attach[i] = attach[part_parent[i]]
		}
	}
	var q int
	fmt.Fscan(in, &q)
	for qi := 0; qi < q; qi++ {
		var t, u, v int
		fmt.Fscan(in, &t, &u, &v)
		if u == v {
			fmt.Println("NO")
			continue
		}
		if t == 1 {
			d := depth[v] - depth[u]
			if d <= 0 {
				fmt.Println("NO")
				continue
			}
			anc := v
			for k := 0; k < LOG; k++ {
				if (d & (1 << k)) != 0 {
					anc = par[k][anc]
					if anc == -1 {
						break
					}
				}
			}
			if anc == u {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		} else {
			xv := attach[v]
			if xv == v {
				fmt.Println("NO")
				continue
			}
			if u == xv {
				fmt.Println("YES")
				continue
			}
			d := depth[u] - depth[xv]
			if d <= 0 {
				fmt.Println("NO")
				continue
			}
			anc := u
			for k := 0; k < LOG; k++ {
				if (d & (1 << k)) != 0 {
					anc = par[k][anc]
					if anc == -1 {
						break
					}
				}
			}
			if anc == xv {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}