# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
729857 | 2023-04-24T18:17:42 Z | kirakaminski968 | Crocodile's Underground City (IOI11_crocodile) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; int solve(int N,int M,int *(edges)[2],int *times,int K,int *positions){ vector<pair<int,int>> adj[N]; for(int i = 0;i<M;++i){ adj[edges[i][0]].push_back({edges[i][1],times[i]}); adj[edges[i][1]].push_back({edges[i][2],times[i]}); } vector<int> vis(N,0); vector<vector<int>> dist(N); priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; for(int i = 0;i<K;++i){ int cur = positions[i]; vis[cur] = 1; dist[cur].push_back(0); dist[cur].push_back(0); pq.push({0,cur}); } while(!pq.empty()){ int u = pq.top().second; int dis = pq.top().first; pq.pop(); if(vis[u] >= 2) continue; vis[u]++; if(vis[u] != 2) continue; if(u == 0) return dis; for(auto p : adj[u]){ int v = p.first; if(dist[v].size() == 2){ if(dist[v][1] >= p.second+dis){ dist[v][1] = p.second+dis; pq.push({p.second+dis,v}); } } else{ dist[v].push_back(p.second+dis); pq.push({p.second+dis,v}); } } } } int travel_plan(int N,int M,int *(R)[2],int *L,int K,int *P){ return solve(N,M,R,L,K,P); }