Submission #1087968

# Submission time Handle Problem Language Result Execution time Memory
1087968 2024-09-13T15:59:16 Z T0p_ Crocodile's Underground City (IOI11_crocodile) C++14
89 / 100
342 ms 93368 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, mn_2[edge.first] });
      }
    }
  }
  return mn_2[0];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2712 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 3 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2712 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 3 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 3 ms 3164 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 4 ms 3420 KB Output is correct
13 Correct 3 ms 3420 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2712 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 3 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 3 ms 3164 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 4 ms 3420 KB Output is correct
13 Correct 3 ms 3420 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 275 ms 85108 KB Output is correct
17 Correct 60 ms 19908 KB Output is correct
18 Correct 70 ms 22216 KB Output is correct
19 Correct 342 ms 93368 KB Output is correct
20 Correct 199 ms 68180 KB Output is correct
21 Correct 33 ms 10440 KB Output is correct
22 Incorrect 224 ms 64720 KB Output isn't correct
23 Halted 0 ms 0 KB -