#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; template struct bellman_ford { struct edge { int from, to; T cost; }; int V; vector d; vector es; T inf() { return numeric_limits::max() / 10; } bellman_ford(int node_size) : V(node_size), d(V, inf()) {} void add_edge(int from, int to, T cost) { es.push_back((edge){from, to, cost}); } // sからの最短路長およびsからたどり着ける負の閉路の検出(trueなら負の閉路が存在する) T solve(int s) { int cnt = 0; d[s] = 0; while (cnt < V) { bool update = false; for (auto &e : es) { if (d[e.from] != inf() && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; } } if (!update) break; cnt++; } return d[V - 1]; } }; int main() { int n, m, q; cin >> n >> m >> q; vector use(m, 1); vector a(m), b(m), c(m); rep(i, 0, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--, b[i]--; } rep(i, 0, q) { int x; cin >> x; x--; use[x] ^= 1; bellman_ford bf(n); rep(j, 0, m) { if (use[j]) bf.add_edge(a[j], b[j], -c[j]); } int ans = bf.solve(0); if (ans == bf.inf()) cout << "NaN" << endl; else cout << -ans << endl; } }