def sol c, d, list if d.empty? return c end x = d.shift ans = [] c.each{|s| list[s][0].each_with_index{|v,i| if v == x ans.push(list[s][1][i]) end } } return sol(ans.uniq, d, list) end n,m,k = gets.split.map(&:to_i) fee = Hash.new([]) list = Array.new(n) n.times{|i| list[i] = Array.new(2) list[i][0] = [] list[i][1] = [] } m.times{ a,b,c = gets.split.map(&:to_i) fee[c] = fee[c] + [a - 1,b - 1] list[a - 1][0].push(c) list[a - 1][1].push(b - 1) list[b - 1][0].push(c) list[b - 1][1].push(a - 1) } d = gets.split.map(&:to_i) x = d.shift ans = sol(fee[x].uniq, d, list).map{|i|i + 1}.sort p ans.size puts ans.join(' ')