Submission #1087966

# Submission time Handle Problem Language Result Execution time Memory
1087966 2024-09-13T15:56:23 Z T0p_ Crocodile's Underground City (IOI11_crocodile) C++14
0 / 100
1 ms 2908 KB
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 100000 + 5;

struct Dijkstra {
  int node;
  long long weight;

  bool operator < (const Dijkstra & o) const {
    return weight > o.weight;
  }
};

long long mn_1[MAX_N], mn_2[MAX_N];
vector<pair<int, long long>> g[MAX_N];

bool update(int u, long long v) {
  if (v < mn_1[u]) {
    mn_2[u] = mn_1[u];
    mn_1[u] = v;
    return true;
  }
  else if (v < mn_2[u]) {
    mn_2[u] = v;
    return true;
  }

  return false;
}

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]].push_back({ R[i][1], L[i] });
    g[R[i][1]].push_back({ R[i][0], L[i] });
  }

  for (int i=0 ; i<N ; i++) {
    mn_1[i] = mn_2[i] = 2e9;
  }

  priority_queue<Dijkstra> dijkstra;

  for (int i=0 ; i<K ; i++) {
    mn_1[P[i]] = mn_2[P[i]] = 0;
    dijkstra.push({ P[i], 0 });
  }

  while (!dijkstra.empty()) {
    int node = dijkstra.top().node;
    long long weight = dijkstra.top().weight;
    dijkstra.pop();

    if (weight != mn_2[node]) continue;

    for (pair<int, long long> edge : g[node]) {
      if (update(edge.first, weight + edge.second) && edge.first != 0) {
        dijkstra.push({ edge.first, weight + edge.second });
      }
    }
  }
  return mn_2[0];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Incorrect 1 ms 2908 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Incorrect 1 ms 2908 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Incorrect 1 ms 2908 KB Output isn't correct
5 Halted 0 ms 0 KB -