#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; vectorg[1005]; int main() { int n, m, k; cin >> n >> m >> k; vector>x[102]; for (int i = 0; i < m; i++) { int a, b, j; cin >> a >> b >> j; a--; b--; x[a].push_back(make_pair(j, b)); x[b].push_back(make_pair(j, a)); } for (int i = 0; i <= n; i++) { g[0].push_back(i); } for (int i = 0; i < k; i++) { int d; cin >> d; for (int j = 0; j < g[i].size(); j++) { for (int w = 0;w< x[g[i][j]].size(); w++) { if (x[g[i][j]][w].first == d)g[i + 1].push_back(x[g[i][j]][w].second); } } } sort(g[n-1].begin(), g[n-1].end()); cout << g[n - 1].size() << endl; for (int i = 0; i < g[n-1].size(); i++) { if (i)cout << " "; cout << g[n-1][i]+1 ; if (i == g[n - 1].size() - 1)cout << endl; } return 0; }