package main import ( "fmt" "strconv" "strings" ) func main() { var n, m, k int fmt.Scan(&n, &m, &k) a := make([]int, m) b := make([]int, m) c := make([]int, m) for i, _ := range a { fmt.Scan(&a[i], &b[i], &c[i]) a[i]-- b[i]-- } ans := make([]bool, n) for i, _ := range ans { ans[i] = true } for i := 0; i < k; i++ { var d int fmt.Scan(&d) next := make([]bool, n) for j, _ := range a { if c[j] != d { continue } if ans[a[j]] { next[b[j]] = true } if ans[b[j]] { next[a[j]] = true } } copy(ans, next) } res := make([]string, 0) for i, v := range ans { if v { res = append(res, strconv.Itoa(i+1)) } } fmt.Println(len(res)) fmt.Println(strings.Join(res, " ")) }