Submission #297764

# Submission time Handle Problem Language Result Execution time Memory
297764 2020-09-11T21:52:54 Z Haunted_Cpp Crocodile's Underground City (IOI11_crocodile) C++17
0 / 100
2 ms 2688 KB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 1e5 + 5;

vector<vector<pair<int, int>>> g(MAX_N);

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
  for (int i = 0; i < M; i++) {
    g[R[i][0]].emplace_back(R[i][1], L[i]);
    g[R[i][1]].emplace_back(R[i][0], L[i]);
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  vector<int> closest_one(N, 1e9);
  for (int i = 0; i < K; i++) {
    closest_one[P[i]] = 0;
    pq.emplace(closest_one[P[i]], P[i]);
  }
  while(!pq.empty()) {
    auto [w, node] = pq.top();
    pq.pop();
    if (w != closest_one[node]) {
      continue;
    }
    for (auto [to, cost] : g[node]) {
      if (closest_one[to] > closest_one[node] + cost) {
        closest_one[to] = closest_one[node] + cost;
        pq.emplace(closest_one[to], to);
      }
    }
  }
  vector<int> dist(N, 1e9);
  dist[0] = 0;
  pq.emplace(dist[0], 0);
  while(!pq.empty()) {
    auto [w, node] = pq.top();
    pq.pop();
    if (w != dist[node]) {
      continue;
    }
    pair<int, int> is_blocked = {1e9, 1e9};
    for (auto [to, cost] : g[node]) {
      is_blocked = min(is_blocked, {closest_one[to] + cost , to});
    }
    for (auto [to, cost] : g[node]) {
      if (to == is_blocked.second) {
        continue;
      }
      if (dist[to] > dist[node] + cost) {
        dist[to] = dist[node] + cost;
        pq.emplace(dist[to], to);
      }
    }
  }
  int best_way = 1e9;
  for (int i = 0; i < K; i++) {
    best_way = min(best_way, dist[P[i]]);
  }
  return best_way;
}


# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -