#include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define pb push_back #define ALL(a) (a).begin(),(a).end() #define EPS (1e-10) #define EQ(a,b) (abs((a)-(b)) < EPS) #define PI 3.1415926535 typedef long long ll; //typedef pair P; //typedef complex C; struct edge { int to, cost; }; const int MAX_N = 100; const int MAX_K = 1000; int N, M, K; vector G[MAX_N]; int d[MAX_K]; void input() { cin >> N >> M >> K; REP(i, M) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].pb((edge){b, c}); G[b].pb((edge){a, c}); } REP(i, K) cin >> d[i]; } void solve() { bool v1[N]; bool v2[N]; REP(i, N) { v1[i] = false; v2[i] = false; } // d_0の両端を最初の候補に入れる REP(i, N) { for (auto e: G[i]) { if (e.cost == d[0]) { v1[i] = true; v1[e.to] = true; } } } FOR(k, 1, K) { REP(i, N) { for (auto e: G[i]) { if (v1[i] && e.cost == d[k]) { v2[e.to] = true; } } } REP(i, N) v1[i] = v2[i]; } vector ans; REP(i, N) { if (v1[i]) { ans.pb(i + 1); } } cout << ans.size() << endl; REP(i, ans.size()) { cout << ans[i] << ' '; } cout << endl; } int main() { input(); solve(); return 0; }