답안 #981952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
981952 2024-05-13T17:05:12 Z kilkuwu 악어의 지하 도시 (IOI11_crocodile) C++17
100 / 100
398 ms 74948 KB
#include "crocodile.h"
 
#include <bits/stdc++.h>
 
#ifdef LOCAL
#include "template/debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif
 
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
#define int int64_t
  std::vector<std::vector<std::pair<int, int>>> adj(N);
 
  for (int i = 0; i < M; i++) {
    int u = R[i][0], v = R[i][1], w = L[i];
    adj[u].emplace_back(v, w);
    adj[v].emplace_back(u, w);
  }
 
  std::vector<std::pair<int, int>> dp(N, {1e9, 1e9});
 
  std::priority_queue<std::pair<int, int>> pq;
 
  for (int i = 0; i < K; i++) {
    dp[P[i]] = {0, 0};
    pq.emplace(0, P[i]);
  }
 
  auto update = [&](int u, int len) -> bool {
    if (len < dp[u].first) {
      int previous = dp[u].second;
      dp[u].second = dp[u].first;
      dp[u].first = len;
      return dp[u].second < previous;
    } else if (len < dp[u].second) {
      dp[u].second = len;
      return true;
    }
    return false;
  };

  while (pq.size()) {
    auto [d, u] = pq.top();
    pq.pop();
 
    d = -d;

    if (d > dp[u].second) continue;
 
    for (auto [v, w] : adj[u]) {
      if (update(v, d + w)) {
        pq.emplace(-dp[v].second, v);
      }  
    }
  }
 
  return dp[0].second;
#undef int
}
 
 
 
#ifdef LOCAL
#include <stdio.h>
#include <stdlib.h>
 
#define MAX_N 50000
#define MAX_M 10000000
 
static int N, M;
static int R[MAX_M][2];
static int L[MAX_M];
static int K;
static int P[MAX_N];
static int solution;
 
inline 
void my_assert(int e) {if (!e) abort();}
 
void read_input()
{
  int i;
  my_assert(3==scanf("%d %d %d",&N,&M,&K));
  for(i=0; i<M; i++)
    my_assert(3==scanf("%d %d %d",&R[i][0],&R[i][1],&L[i]));
  for(i=0; i<K; i++)
    my_assert(1==scanf("%d",&P[i]));
  my_assert(1==scanf("%d",&solution));
}
 
int main()
{
  int ans;
  read_input();
  ans = travel_plan(N,M,R,L,K,P);
  if(ans==solution)
    printf("Correct.\n");
  else
    printf("Incorrect. Returned %d, Expected %d.\n",ans,solution);
 
  return 0;
}
 
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 3 ms 4700 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 3 ms 5068 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 3 ms 4700 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 3 ms 5068 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 307 ms 65992 KB Output is correct
17 Correct 52 ms 16208 KB Output is correct
18 Correct 69 ms 18352 KB Output is correct
19 Correct 398 ms 74948 KB Output is correct
20 Correct 219 ms 53416 KB Output is correct
21 Correct 29 ms 9820 KB Output is correct
22 Correct 222 ms 50212 KB Output is correct