#include #include #include #include #include #include #include using namespace std; int main() { int n, m, k; cin >> n >> m >> k; vector< vector< set > > price(n + 1, vector< set >(n + 1)); int a, b, c; for (int i = 0; i < m; i++) { cin >> a >> b >> c; price[a][b].insert(c); price[b][a].insert(c); } vector< vector > possible(k + 1, vector(n + 1, false)); fill(possible[0].begin() + 1, possible[0].end(), true); int d; for (int i = 0; i < k; i++) { cin >> d; for (int j = 0; j <= n; j++) { if (!possible[i][j]) { continue; } for (int h = 1; h <= n; h++) { if (price[j][h].count(d) > 0) { possible[i + 1][h] = true; } } } } vector ans; for (int i = 0; i <= n; i++) { if (possible[k][i]) { ans.push_back(i); } } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { if (i != 0) { cout << " "; } cout << ans[i]; } cout << endl; return 0; }