#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair P; const ll INF = 1ll<<61; const ll MOD = 1000000007; const double EPS = 1e-10; int n, m, K; map > g; int main() { cin >> n >> m >> K; REP(i, m) { int a, b, c; scanf("%d %d %d", &a, &b, &c); a--; b--; g[c].push_back(pii(a, b)); g[c].push_back(pii(b, a)); } vector ans; REP(i, n) ans.push_back(i); REP(i, K) { int d; scanf("%d", &d); vector &gn = g[d]; vector now; REP(j, ans.size()) { REP(k, gn.size()) if (gn[k].first == ans[j]) now.push_back(gn[k].second); } ans = now; } sort(ALL(ans)); ans.erase(unique(ALL(ans)), ans.end()); cout << ans.size() << endl; REP(i, ans.size()) printf("%d%c", ans[i] + 1, i == ans.size() - 1 ? '\n' : ' '); return 0; }