답안 #786882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786882 2023-07-18T14:11:46 Z jakobrs 악어의 지하 도시 (IOI11_crocodile) C++17
100 / 100
356 ms 72964 KB
#include "crocodile.h"

#include <tuple>
#include <utility>
#include <iostream>
#include <queue>
#include <vector>

using i64 = int64_t;

struct Node {
  i64 dist;
  i64 index;

  bool operator<(const Node &rhs) const {
    return std::tie(rhs.dist, index) < std::tie(dist, rhs.index);
  }
};

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
  std::vector<std::vector<std::pair<i64, i64>>> adj(N);
  for (i64 i = 0; i < M; i++) {
    adj[R[i][0]].push_back({R[i][1], L[i]});
    adj[R[i][1]].push_back({R[i][0], L[i]});
  }

  std::vector<i64> distances(N, 1e18);
  std::vector<i64> distances2(N, 1e18);
  std::priority_queue<Node> pq;
  for (i64 i = 0; i < K; i++) {
    distances[P[i]] = 0;
    distances2[P[i]] = 0;
    pq.push(Node{.dist = 0, .index = P[i]});
  }
  while (!pq.empty()) {
    auto [dist, index] = pq.top();
    pq.pop();

    if (dist > distances2[index])
      continue;
    if (index == 0)
      return dist;

    for (auto [x, d] : adj[index]) {
      i64 new_dist = dist + d;
      if (new_dist < distances[x]) {
        if (distances[x] < distances2[x]) {
          pq.push(Node{.dist = distances[x], .index = x});
        }
        distances2[x] = distances[x];
        distances[x] = new_dist;
      } else if (new_dist < distances2[x]) {
        distances2[x] = new_dist;

        pq.push(Node{.dist = new_dist, .index = x});
      }
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 280 KB Output is correct
4 Correct 1 ms 392 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 280 KB Output is correct
4 Correct 1 ms 392 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 3 ms 852 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 280 KB Output is correct
4 Correct 1 ms 392 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 3 ms 852 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 299 ms 65400 KB Output is correct
17 Correct 54 ms 14284 KB Output is correct
18 Correct 64 ms 16660 KB Output is correct
19 Correct 356 ms 72964 KB Output is correct
20 Correct 223 ms 52672 KB Output is correct
21 Correct 32 ms 6604 KB Output is correct
22 Correct 235 ms 48212 KB Output is correct