Submission #844053

#TimeUsernameProblemLanguageResultExecution timeMemory
844053Darren0724Evacuation plan (IZhO18_plan)C++17
23 / 100
333 ms28124 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int INF = 1e9;
vector<pair<int, int>> adj[N];
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }
    vector<int> dis(N, INF);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    int shaoji;
    cin >> shaoji;
    for (int i = 0; i < shaoji; i++) {
        int k;
        cin >> k;
        dis[k]=0;
        pq.push({0,k});
    }
    while(pq.size()){
        int a,b;tie(a,b)=pq.top();
        pq.pop();
        if(a!=dis[b]){
            continue;
        }
        for(auto &e:adj[b]){
            if(dis[e.first]>a+e.second){
                dis[e.first]=a+e.second;
                pq.push({dis[e.first],e.first});
            }
        }
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
        int a,b;cin>>a>>b;
        cout<<min(dis[a],dis[b])<<endl;
    }

    return 0;
}
/*
9 12
1 9 4
1 2 5
2 3 7
2 4 3
4 3 6
3 6 4
8 7 10
6 7 5
5 8 1
9 5 7
5 4 12
6 8 2
2
4 7
*/
#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...