#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; static const double EPS = 1e-8; static const double PI = 4.0 * atan(1.0); static const double PI2 = 8.0 * atan(1.0); typedef long long ll; typedef unsigned long long ull; #define ALL(c) (c).begin(), (c).end() #define CLEAR(v) memset(v,0,sizeof(v)) #define MP(a,b) make_pair((a),(b)) #define REP(i,n) for(int i=0;i<(int)n;++i) #define ABS(a) ((a)>0?(a):-(a)) template T MIN(const T& a, const T& b) { return a < b ? a : b; } template T MAX(const T& a, const T& b) { return a > b ? a : b; } template void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; } template void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; } int main() { std::ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; vector > > graph(N + 1); REP(m, M) { int a, b, c; cin >> a >> b >> c; graph[a].push_back(MP(b, c)); graph[b].push_back(MP(a, c)); } bool dp[2][128]; CLEAR(dp); int front = 0; int back = 1; REP(n, N + 1) { dp[back][n] = 1; } REP(k, K) { int d; cin >> d; REP(n, N + 1) { dp[front][n] = false; } for (int from = 1; from <= N; ++from) { for (const auto& edge : graph[from]) { if (edge.second != d) { continue; } dp[front][edge.first] |= dp[back][from]; } } swap(front, back); } vector answer; REP(n, N) { if (dp[back][n + 1]) { answer.push_back(n + 1); } } cout << answer.size() << endl; REP(i, answer.size()) { if (i) { cout << " "; } cout << answer[i]; } cout << endl; }