제출 #868799

#제출 시각아이디문제언어결과실행 시간메모리
86879912345678Evacuation plan (IZhO18_plan)C++17
22 / 100
4025 ms13780 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5;
int n, m, u, v, w, k, x, q, s, t, mn[nx];
vector<pair<int, int>> d[nx];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=m; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w});
    for (int i=1; i<=n; i++) mn[i]=1e9;
    cin>>k;
    for (int i=1; i<=k; i++) cin>>x, mn[x]=0, pq.push({0, x});
    while (!pq.empty())
    {
        auto [cw, cl]=pq.top();
        pq.pop();
        for (auto [nl, nw]:d[cl]) if (cw+nw<mn[nl]) mn[nl]=cw+nw, pq.push({cw+nw, nl});
    }
    cin>>q;
    while (q--)
    {
        cin>>s>>t;
        vector<int> dp(n+1);
        dp[s]=mn[s];
        pq.push({dp[s], s});
        while (!pq.empty())
        {
            auto [cw, cl]=pq.top();
            pq.pop();
            for (auto [nl, nw]:d[cl]) if (min(dp[cl], mn[nl])>dp[nl]) dp[nl]=min(dp[cl], mn[nl]), pq.push({min(dp[cl], mn[nl]), nl});
        }
        cout<<dp[t]<<'\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...