#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; template struct fenwick_tree { fenwick_tree(int n) { this->n = n; dat = vector(n); } void add(int i, T x) { i++; while (i <= n) { dat[i - 1] += x; i += i & -i; } } T operator[](int i) { return sum(i, i + 1); } T sum(int l, int r) { return sum(r) - sum(l); } friend ostream &operator<<(ostream &os, fenwick_tree A) { int n = A.n; os << "[ "; for (int i = 0; i < n; i++) { os << A[i]; if (i != n - 1) os << ", "; } os << " ]"; return os; } private: int n; vector dat; T sum(int r) { T ret = 0; while (r > 0) { ret += dat[r - 1]; r -= r & -r; } return ret; } }; int main() { int N, M, K; cin >> N >> M >> K; vector S(K + 1); for (int i = 0; i <= K; i++) cin >> S[i], S[i]--; vector> G(N, vector(N, LLONG_MAX / 10)); for (int i = 0; i < M; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; G[u][v] = G[v][u] = w; } for (int i = 0; i < N; i++) G[i][i] = 0; for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { G[i][j] = min(G[i][j], G[i][k] + G[k][j]); } } } fenwick_tree fw(K); for (int i = 0; i < K; i++) fw.add(i, G[S[i]][S[i + 1]]); int Q; cin >> Q; while (Q--) { int t, x, y; cin >> t >> x >> y; if (t == 1) { y--; if (x > 0) { fw.add(x - 1, -G[S[x - 1]][S[x]]); fw.add(x - 1, G[S[x - 1]][y]); } if (x < K) { fw.add(x, -G[S[x]][S[x + 1]]); fw.add(x, G[y][S[x + 1]]); } S[x] = y; } else { if (x == y) { cout << 0 << '\n'; } else { cout << fw.sum(x, y) << '\n'; } } debug(fw); } }