#include using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) ll n, m, k; vector>> g; vector d; vector> dp; void dfs(ll v, ll depth = 0) { if (dp[v][depth]) return; dp[v][depth] = true; if (depth == (k - 1)) return; for(auto x : g[v]) { ll u = x.first, c = x.second; if (d[depth + 1] == c) { dfs(u, depth + 1); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); cin >> n >> m >> k; g.resize(n); rep(i, m) { ll a, b, c; cin >> a >> b >> c; a--; b--; g[a].push_back(make_pair(b, c)); g[b].push_back(make_pair(a, c)); } d.resize(k); rep(i, k) cin >> d[i]; dp.resize(n, vector(k, false)); rep(v, n) { for(auto x : g[v]) { ll u = x.first, c = x.second; if (c == d[0]) dfs(u); } } vector ans; rep(i, n) { if (dp[i][k - 1]) ans.push_back(i); } printf("%lld\n", sz(ans)); rep(i, sz(ans)) printf("%lld%s", ans[i] + 1, (i == (sz(ans) - 1)) ? "\n" : " "); return 0; }