#coding: utf-8 #yuki_92 n,m,k=map(int,raw_input().split()) edge=[[] for i in xrange(n)] s=set([]) for i in xrange(m): a,b,c=map(int,raw_input().split()) edge[a-1].append((b-1,c)) edge[b-1].append((a-1,c)) d=map(int,raw_input().split()) for i in xrange(n): for j,c in edge[i]: if c==d[0]: s.add(i) for i in xrange(1,k): t=set([]) for k in s: for j,c in edge[k]: if c==d[i]: t.add(j) s=t res=list(s) print len(res) res.sort() for i in res: print i+1,