# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
172995 | 2020-01-03T00:10:33 Z | FieryPhoenix | Crocodile's Underground City (IOI11_crocodile) | C++11 | 0 ms | 0 KB |
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <cstdio> #include <map> #include <queue> #include <set> #include <iomanip> #include <deque> #include <cassert> #include <ctime> #include <cstring> #include <cstdlib> #include <chrono> #include <ctime> #include <random> #include <stack> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef long double ld; #define INF 2001001001001001 #define MOD 1000000007 bool visited[100001],cut[100001]; vector<pair<int,int>>adj[100001]; ll dis[100001]; priority_queue<pair<ll,ll>>pq; //-dis, node void dijkstra(int K, int P[]){ for (int i=0;i<K;i++){ cut[P[i]]=true; dis[P[i]]=0; pq.push({0,P[i]}); } while (!pq.empty()){ ll d=-pq.top().first; int cur=pq.top().second; pq.pop(); if (!cut[cur]){ cut[cur]=true; continue; } if (visited[cur]) continue; visited[cur]=true; dis[cur]=d; for (auto x:adj[cur]){ if (!visited[x.first]) pq.push({-(d+x.second),x.first}); } } } int travel_plan(int N, int M, int R[][], int L[], int K, int P[]){ for (int i=0;i<M;i++){ adj[R[i][0]].push_back({R[i][1],L[i]}); adj[R[i][1]].push_back({R[i][0],L[i]}); } for (int i=0;i<N;i++) dis[i]=INF; dijkstra(K,P[]); return dis[0]; }