n, m ,k = list(map(int, input().split(' '))) abcm = [None] * m for i in range(m): abcm[i] = list(map(int, input().split(' '))) dk = list(map(int, input().split(' '))) def solver(cp, x): if x == k: return cp for i in range(m): bg = abcm[i] if bg[0] == cp and bg[2] == dk[x]: r = solver(bg[1], x + 1) return r if bg[1] == cp and bg[2] == dk[x]: r = solver(bg[0], x + 1) return r return None c = 0 cps = set() for i in range(1, n + 1): result = solver(i, 0) if result is not None: c += 1 cps.add(result) cps = sorted(cps) print(c) for i in range(c): print(cps[i] ,end=' ') print()