Submission #981770

# Submission time Handle Problem Language Result Execution time Memory
981770 2024-05-13T14:29:14 Z kaopj Evacuation plan (IZhO18_plan) C++14
0 / 100
105 ms 19904 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int,int>> edge[100001];
int n,m;
int dist[100001];
bool vis[100001];
int dfs(int x,int t) {
    vis[x]=1;
    if (!dist[t]) {
        return 0;
    }
    if (t == x||!dist[x]) {
        return dist[x];
    }
    int maxi=0;
    for (auto i:edge[x]) {
        if (vis[i.second]) {
            continue;
        }
        maxi = max(maxi,dfs(i.second,t));
    }
    return min(dist[x],maxi);
}
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    int x,y,d;
    for (int i =0;i<m;i++) {
        cin >> x >> y >> d;
        edge[x].push_back({d,y});
        edge[y].push_back({d,x});
    }
    int q;
    cin >> q;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    for (int i=0;i<=n;i++) {
        dist[i] = 1e9;
    }
    while (q--) {
        cin >> x;
        pq.push({0,x});
        dist[x]=0;
    }
    while (!pq.empty()) {
        auto u = pq.top();
        pq.pop();
        if (dist[u.second] < u.first) {
            continue;
        }
        for (auto i:edge[u.second]) {
            if (dist[i.second] > i.first+u.first) {
                dist[i.second] = i.first+u.first;
                pq.push({dist[i.second],i.second});
            }
        }
    }
    cin >> q;
    while (q--) {
        memset(vis,0,sizeof vis);
        cin >> x >> y;
        cout << dfs(x,y) << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 105 ms 19904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -