#include #include #include template struct Edge { int src, dst; Cost cost; Edge(int src = -1, int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge& e) const { return this->cost < e.cost; } bool operator>(const Edge& e) const { return this->cost > e.cost; } }; template using Graph = std::vector>>; void solve() { int n, m, k; std::cin >> n >> m >> k; Graph<> graph(n); while (m--) { int u, v, c; std::cin >> u >> v >> c; --u, --v; graph[u].emplace_back(u, v, c); graph[v].emplace_back(v, u, c); } std::vector dp(n, true); auto ndp = dp; while (k--) { int d; std::cin >> d; std::fill(ndp.begin(), ndp.end(), false); for (int v = 0; v < n; ++v) { if (!dp[v]) continue; for (auto e : graph[v]) { if (e.cost == d) ndp[e.dst] = true; } } std::swap(dp, ndp); } std::cout << std::accumulate(dp.begin(), dp.end(), 0) << std::endl; for (int v = 0; v < n; ++v) { if (dp[v]) std::cout << v + 1 << " "; } std::cout << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }