#include #define rep(i, n) for(long long i = 0; i < n; i++) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; template struct Edge { int from, to; T cost; int idx; Edge() {} Edge(int to_) : to(to_) {} Edge(int to_, T cost_) : to(to_), cost(cost_) {} Edge(int from_, int to_, int idx_) : from(from_), to(to_), idx(idx_) {} Edge(int from_, int to_, T cost_, int idx_) : from(from_), to(to_), cost(cost_), idx(idx_) {} }; template using Graph = vector>>; using graph = Graph; using edge = Edge; #define add emplace_back vector BellmanFord(graph g, int s) { int n = g.size(); long long INF = 1000000000000000000; vector dist(n, INF); vector nega(n, false); dist[s] = 0; for (int step = 0; step < n - 1; step++) { bool update = false; for (int u = 0; u < n; u++) { if (dist[u] == INF) { continue; } for (auto e : g[u]) { int v = e.to; long long w = e.cost; if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; update = true; } } } if (!update) { break; } } for (int step = 0; step < n; step++) { for (int u = 0; u < n; u++) { if (dist[u] == INF) { continue; } for (auto e : g[u]) { int v = e.to; long long w = e.cost; if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; nega[v] = true; } if (nega[u]) { nega[v] = true; } } } } for (int v = 0; v < n; v++) { if (nega[v]) { dist[v] = -INF; } } return dist; } struct Dijkstra { private: graph g; int n, s; vector d; vector prev; vector visit; priority_queue, vector>, greater>> pq; public: Dijkstra(graph g_, int s_) : g(g_), n(g.size()), s(s_), d(n, 1000000000000000000), prev(n), visit(n, false) { d[s] = 0LL; pq.emplace(d[s], s); while (!pq.empty()) { int v = pq.top().second; pq.pop(); if (visit[v]) { continue; } visit[v] = true; for (auto e : g[v]) { int nv = e.to; long long nc = e.cost; if (d[nv] > d[v] + nc) { d[nv] = d[v] + nc; prev[nv] = e; pq.emplace(d[nv], nv); } } } } vector dists() { return d; } long long dist(int t) { return d[t]; } vector route(int t) { if (s == t || d[t] == 1000000000000000000) { return {}; } vector res; int cur = t; while (cur != s) { res.emplace_back(prev[cur]); cur = prev[cur].from; } reverse(res.begin(), res.end()); return res; } }; int main() { int n, m, q; cin >> n >> m >> q; graph g(n); vector es; rep(i, m) { int u, v; lint w; cin >> u >> v >> w; u--; v--; w *= -1LL; g[u].add(v, w); es.emplace_back(u, v, w, i); } auto p = BellmanFord(g, 0); rep(i, n) { p[i] *= -1LL; } vector exist(m, 1); while (q--) { int j; cin >> j; j--; exist[j] ^= 1; graph gg(n); rep(i, m) { if (exist[i] == 1) { auto e = es[i]; int u = e.from, v = e.to; lint w = e.cost; w -= p[u] - p[v]; gg[u].add(v, w); } } lint ans = Dijkstra(gg, 0).dist(n - 1); if (ans == 1000000000000000000) { cout << "NaN" << endl; } else { ans -= p[n - 1]; cout << -ans << endl; } } }