// {{{ Templates #include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; template constexpr T INF = numeric_limits::max() / 100; // }}} struct Edge { int from; int to; ll cost; bool operator<(const Edge& e) const { return cost < e.cost; } }; struct Graph { Graph(int n) { edge.resize(n); } void addEdge(int from, int to, ll cost) { edge[from].insert(Edge{from, to, cost}); edge[to].insert(Edge{to, from, cost}); } vector> edge; }; int N, M, K; bool dfs(const Graph& g, const int pos, const int tim, const vector& d) { if (tim == K) { return true; } const ll cost = d[tim]; auto it = g.edge[pos].find(Edge{0, 0, cost}); if (it == g.edge[pos].end()) { return false; } else { for (; it != g.edge[pos].end() and it->cost == cost; it++) { if (dfs(g, it->to, tim + 1, d)) { return true; } } return false; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M >> K; Graph g(N); for (int i = 0; i < M; i++) { int a, b; ll c; cin >> a >> b >> c; a--, b--; g.addEdge(a, b, c); } vector d(K); for (int i = 0; i < K; i++) { cin >> d[i]; } reverse(d.begin(), d.end()); vector ans; for (int i = 0; i < N; i++) { if (dfs(g, i, 0, d)) { ans.push_back(i + 1); } } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { if (i != 0) { cout << " "; } cout << ans[i]; } cout << endl; return 0; }