Submission #1216537

#TimeUsernameProblemLanguageResultExecution timeMemory
1216537kiennguyendinhCrocodile's Underground City (IOI11_crocodile)C++17
0 / 100
1 ms2624 KiB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
int n, m, x, y;
long long w, inf = 1e18;
vector<pair<int, long long>> adj[100001];
long long dist[100001][2];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    for (int i = 0; i < M; i++) {
        x = R[i][0], y = R[i][1], w = L[i];
        adj[x].push_back({y, w});
        adj[y].push_back({x, w});
    }
    for (int i = 0; i < N; i++) dist[i][0] = dist[i][1] = inf;
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
    for (int i = 0; i < K; i++) {
        dist[P[i]][0] = dist[P[i]][1] = 0;
        q.push({0, P[i]});
    }
    while (!q.empty()) {
        long long val = q.top().second;
        int u = q.top().first;
        q.pop();
        for (pair<int, long long> v : adj[u]) {
            if (dist[v.first][1] > val + v.second) {
                dist[v.first][1] = val + v.second;
                if (dist[v.first][0] > dist[v.first][1]) swap(dist[v.first][0], dist[v.first][1]);
                q.push({val + v.second, v.first});
            }
        }
    }
    return dist[0][1];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...