제출 #1241002

#제출 시각아이디문제언어결과실행 시간메모리
1241002guanex악어의 지하 도시 (IOI11_crocodile)C++20
89 / 100
307 ms77056 KiB
#include "crocodile.h"
#include<bits/stdc++.h>

using namespace std;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
  vector<vector<pair<long long, long long>>> ed(N);
  for(long long i = 0; i < M; ++i){
    ed[R[i][0]].push_back({R[i][1], L[i]});
    ed[R[i][1]].push_back({R[i][0], L[i]});
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq;
  vector<pair<long long, long long>> paths(N, make_pair(1e18, 1e18));
  for(int i = 0; i < K; ++i){
    paths[P[i]] = {0, 0};
    pq.push({0, P[i]});
  }
  while(!pq.empty()){
    long long no = pq.top().second;
    long long dis = pq.top().first;
    pq.pop();
    if(paths[no].second < dis){
      continue;
    }
    //cout << no << " " << dis << endl;
    for(auto e:ed[no]){
      if(dis + e.second < paths[e.first].first){
        paths[e.first].second = paths[e.first].first;
        paths[e.first].first = dis + e.second;
        pq.push({paths[e.first].second, e.first});
      }else if(dis + e.second < paths[e.first].second){
        paths[e.first].second = dis + e.second;
        pq.push({paths[e.first].second, e.first});
      }
    }
  }
  return paths[0].second;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...