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] result = [] for i in range(m): bg = abcm[i] if bg[0] == cp and bg[2] == dk[x]: r = solver(bg[1], x + 1) if len(r) != 0: result.extend(r) elif bg[1] == cp and bg[2] == dk[x]: r = solver(bg[0], x + 1) if len(r) != 0: result.extend(r) return result c = 0 cps = set() for i in range(1, n + 1): result = solver(i, 0) c += len(result) for j in result: cps.add(j) cps = sorted(cps) print(c) for i in range(c): print(cps[i] ,end=' ') print()