답안 #1087965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087965 2024-09-13T15:54:41 Z T0p_ 악어의 지하 도시 (IOI11_crocodile) C++14
0 / 100
2 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)) {
        dijkstra.push({ edge.first, weight + edge.second });
      }
    }
  }
  return mn_2[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2820 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2820 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2820 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 -