제출 #569367

#제출 시각아이디문제언어결과실행 시간메모리
569367codebuster_10악어의 지하 도시 (IOI11_crocodile)C++17
100 / 100
629 ms61076 KiB
#include <bits/stdc++.h>
using namespace std ;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){

  const int inf = 2e9;

  vector<pair<int,int>> dis(N,{inf,inf});

  vector<vector<pair<int,int>>> g(N);

  for(int e = 0; e < M; ++e){
    int u = R[e][0], v = R[e][1], w = L[e];
    g[u].emplace_back(v,w);
    g[v].emplace_back(u,w);
  }

  priority_queue<pair<int,int>> pq;

  for(int i = 0; i < K; ++i){
    int u = P[i];
    dis[u] = {0,0};
    pq.push({-dis[u].second,u});
  }

  while(!pq.empty()){
    auto [d,i] = pq.top(); pq.pop();

    if(-d != dis[i].second)
      continue;

    for(auto [j,w] : g[i]){
      vector<int> prv = {dis[j].first,dis[j].second};
      prv.push_back(w + dis[i].second);
      auto now = prv;
      sort(now.begin(), now.end());
      dis[j].first = now[0];
      dis[j].second = now[1];

      if(prv[1] != now[1]){
        pq.push({-dis[j].second,j});
      }
    }

  }

  return dis[0].second;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...