# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
530988 | mat50013 | 악어의 지하 도시 (IOI11_crocodile) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<int, int> > G[MAX_N + 5];
ll dist[MAX_N + 5];
bool waiting[MAX_N + 5], viz[MAX_N + 5];
bool cmp(pair<int, int> a, pair<int, int> b)
{
return (dist[a.first] + a.second) < (dist[b.first] + b.second);
}
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)
dist[i] = LLONG_MAX / 2;
queue<int> q;
for(int i = 0; i < K; ++i)
{
dist[P[i]] = 0;
q.push(P[i]);
}
while(!q.empty())
{
int nd = q.front();
q.pop();
waiting[nd] = 0;
for(auto it: G[nd])
if(dist[nd] + it.second < dist[it.first])
{
dist[it.first] = dist[nd] + it.second;
if(!waiting[it.first])
{
q.push(it.first);
waiting[it.first] = 1;
}
}
}
int timp = 0, curNd = 0;
viz[curNd] = 1;
while(dist[curNd] != 0)
{
sort(G[curNd].begin(), G[curNd].end(), cmp);
for(int i = 1; i < (G[curNd].size()); ++i)
if(!viz[G[curNd][i].first])
{
timp += G[curNd][i].second;
curNd = G[curNd][i].first;
viz[curNd] = 1;
break;
}
}
return timp;
}