#include #include #include #include #include using namespace std; int8_t N; int16_t M, K; vector> G[100]; int32_t D[1000]; bitset<100> dp[1001]; int main() { scanf("%hhd%hd%hd", &N, &M, &K); while(M--) { int8_t A, B; int32_t C; scanf("%hhd%hhd%d", &A, &B, &C); --A, --B; G[A].emplace_back(B, C); G[B].emplace_back(A, C); } for(int i = 0; i < K; ++i) scanf("%d", &D[i]); dp[0].set(); for(int16_t t = 0; t < K; ++t) { dp[t + 1].reset(); for(int8_t v = 0; v < N; ++v) if(dp[t][v]) { for(const auto e : G[v]) dp[t + 1][e.first] = dp[t + 1][e.first] | (e.second == D[t]); } } vector ans; for(int8_t v = 0; v < N; ++v) if(dp[K][v]) ans.push_back(v); printf("%u\n", ans.size()); for(const auto x : ans) printf("%d ", x + 1); printf("\n"); }