#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 2e5 + 7;
const int R = 1e9 + 10;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int B = 320;
vector < pair < int, int >> g[N];
bool used[N];
ll dist[N];
void solve() {
	int n, m;
	cin >> n >> m;
	
	for (int i = 1; i <= m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		
		g[u].pb({v, w});
		g[v].pb({u, w});
	}
	
	int atom;
	cin >> atom;
	
	for (int i = 1;i <= n; i++) {
		dist[i] = INF;
	}
	
	priority_queue < pair < int, int > > q;
	for (int i = 1; i <= atom; i++) {
		int x;
		cin >> x;
		q.push({0, x});
		// used[x] = true;
		dist[x] = 0;
	}
	
	while (q.size()) {
		int a = q.top().S; q.pop();
		
		if (used[a]) continue;
		used[a] = true;
		
		for (auto v : g[a]) {
			int b = v.F, w = v.S;
			if (dist[a] + w < dist[b]) {
				dist[b] = dist[a] + w;
				q.push({-dist[b], b});
			}
		}
	}
	
	// for (int i = 1; i <= n; i++) {
		// cout << dist[i] << ' ';
	// }
	//8 3 6 0 8 5 0 7 12 
	
	int z;
	cin >> z;
	while (z--) {
		int s, t;
		cin >> s >> t;
		
		cout << min(dist[s], dist[t]) << '\n';
	}
	
}
int main() {
  	// freopen("gates.in", "r", stdin);
  	// freopen("gates.out", "w", stdout);
  	Fast
  
  	int tc = 1;
  	// cin >> tc;
  
  	while (tc--) {
    	solve();
  	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |