This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > pii;
typedef pair < long long, long long > pll;
const int N = 1e5 + 7, inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int X[] = {1, -1, 0, 0};
const int Y[] = {0, 0, 1, -1};
int n, m, d[N], k, ans, us[N], s, t;
vector < pii > g[N];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        d[i] = inf;
    }
    for (int i = 1, u, v, x; i <= m; i++) {
        cin >> u >> v >> x;
        g[u].push_back(make_pair(v, x));
        g[v].push_back(make_pair(u, x));
    }
    set < pair <int, int> > st;
    cin >> k;
    for (int i = 1, x; i <= k; i++) {
        cin >> x;
        d[x] = 0;
        st.insert(make_pair(0, x));
    }
    while(!st.empty()) {
        int x = st.begin() -> second;
        st.erase(st.begin());
        for (int i = 0; i < g[x].size(); ++i) {
            int to = g[x][i].first, len = g[x][i].second;
            if (d[x] + len < d[to]) {
                st.erase(make_pair(d[to], to));
                d[to] = d[x] + len;
                st.insert(make_pair(d[to], to));
            }
        }
    }
    int q;
    cin >> q;
    while(q--) {
        cin >> s >> t;
        cout << min(d[s], d[t]) << '\n';
    }
    return 0;
}
Compilation message (stderr)
plan.cpp: In function 'int main()':
plan.cpp:41:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < g[x].size(); ++i) {
                         ~~^~~~~~~~~~~~~| # | 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... |