제출 #14781

#제출 시각아이디문제언어결과실행 시간메모리
14781minsu악어의 지하 도시 (IOI11_crocodile)C++14
100 / 100
666 ms171776 KiB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vi;
const int MAXN = 111111;
int visit[MAXN]; vi linkd[MAXN]; priority_queue<ii> pq;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
  for(int i=0; i<N; i++) linkd[i].clear();
  memset( visit, 0, sizeof visit);
  for(int i=0; i<M; i++){
    linkd[ R[i][0] ].push_back( { R[i][1], L[i] } );
    linkd[ R[i][1] ].push_back( { R[i][0], L[i] } );
  }
  for(int i=0; i<K; i++) pq.push( { 0, P[i] } ), visit[ P[i] ] = 1;
  while(!pq.empty()){
    int here = pq.top().second, d = -pq.top().first; pq.pop();
    if( ++visit[here] != 2 ) continue;
    if( here == 0 ) return d;
    for(auto it : linkd[here])
      pq.push( { -d-it.second, it.first } );
  }
  return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...