#include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair dpstate; typedef pair edge; typedef pair pll; dpstate merge(dpstate lhs, dpstate rhs) { if(lhs.first > rhs.first) return lhs; if(rhs.first > lhs.first) return rhs; return {lhs.first, min(2, lhs.second + rhs.second)}; } vector edges[200005]; dpstate dp[200005]; // ll dist[200005]; int par[200005]; bool relax(int src, int dst, ll w, const vector& weights) { bool ret = (dist[dst] > dist[src] + w); if(ret) { dist[dst] = dist[src] + w; par[dst] = src; dp[dst] = {-1, -1}; dpstate curr = dp[src]; if(curr.first < weights.size() && weights[curr.first] == dist[dst]) curr.first++; dp[dst] = merge(dp[dst], curr); return true; } if(dist[dst] == dist[src] + w) { dpstate curr = dp[src]; if(curr.first < weights.size() && weights[curr.first] == dist[dst]) curr.first++; dp[dst] = merge(dp[dst], curr); } return false; } void solve() { int n, m, k; cin >> n >> m >> k; for(int i = 0; i < m; i++) { int a, b; ll w; cin >> a >> b >> w; edges[a].emplace_back(b, w); } vector weights; { for(int i = 0; i < k; i++) { ll x; cin >> x; weights.push_back(x); } sort(weights.begin(), weights.end()); if(weights[0] == 0) weights.erase(weights.begin()); } memset(dp, -1, sizeof(dp)); dp[1] = {0, 1}; priority_queue q; fill(dist, dist + n + 1, 2e18); dist[1] = 0; q.emplace(0, 1); while(q.size()) { auto [w, v] = q.top(); q.pop(); w *= -1; if(dist[v] != w) continue; for(edge e: edges[v]) { if(relax(v, e.first, e.second, weights)) { q.emplace(-dist[e.first], e.first); } } } if(dp[n].first != weights.size()) { cout << "0\n"; return; } if(dp[n].second != 1) { assert(dp[n].second == 2); cout << "1\n"; return; } vector path; path.push_back(n); while(path.back() != 1) path.push_back(par[path.back()]); reverse(path.begin(), path.end()); cout << path.size() << "\n"; for(int i = 0; i < path.size(); i++) cout << path[i] << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }