제출 #343665

#제출 시각아이디문제언어결과실행 시간메모리
343665SprdaloEvacuation plan (IZhO18_plan)C++17
23 / 100
469 ms37996 KiB
#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

const int maxn = 1e5+5;
vp e[maxn];

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; ++i){
        int u, v, w;
        cin >> u >> v >> w;

        e[u].push_back({v, w});
        e[v].push_back({u, w});
    }

    int k;
    cin >> k;

    queue<pi> q;
    vi d(n+1,INT64_MAX/10);
    for (int i = 0; i < k; ++i){
        int x;
        cin >> x;
        d[x] = 0;
        q.push({0, x});
    }

    while(!q.empty()){
        int c = q.front().second, dist = q.front().first;
        q.pop();

        if (d[c] < dist) continue;


        for (pi p : e[c]){
            if (d[p.first] > p.second + dist){
                d[p.first] = p.second+dist;
                q.push({d[p.first], p.first});
            }
        }
    }

    int Q;
    cin >> Q;

    for (int i = 0; i < Q; ++i){
        int u, v;
        cin >> u >> v;
        cout << min(d[u], d[v]) << '\n';
    }
}

/*
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
5
1 6
5 3
4 8
5 8
1 5
*/
#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...