#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(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 inf 0x3f3f3f3f #define CLEAR(a) a = decltype(a)() #define MP make_pair #define ALL(a) (a).begin(),(a).end() #define pii pair #define pcc pair #define pic pair #define pci pair #define VS vector #define VI vector #define DEBUG(x) cout<<#x<<": "<> N >> M >> K; vector > e(N); vector d(K); REP(i, M) { int a, b, c; cin >> a >> b >> c; --a; --b; e[a].emplace_back(b, c); e[b].emplace_back(a, c); } for (auto &a : d) cin >> a; bool vis[1001][100] = {}; REP(i, N) vis[0][i] = true; REP(k, K) { for (int i = 0; i < N; ++i) { if (vis[k][i]) { for (auto &a : e[i]) { if (a.c == d[k]) vis[k + 1][a.to] = true; } } } } vector res; REP(i, N) if (vis[K][i]) res.push_back(i); cout << res.size() << endl; REP(i, res.size()) { cout << res[i]+1 << (i == res.size() - 1 ? "\n" : " "); } return 0; }