Submission #426109

#TimeUsernameProblemLanguageResultExecution timeMemory
426109someoneCrocodile's Underground City (IOI11_crocodile)C++14
100 / 100
930 ms77984 KiB
#include "crocodile.h" #include <bits/stdc++.h> #define ll long long using namespace std; struct Node { ll i, t; bool operator <(const Node& other) const { return t > other.t; } }; const ll N = 1e5 + 10, INF = 1e18; priority_queue<Node> q; vector<ll> adj[N], len[N]; ll n, m, dist[N][2]; void Dijkstra() { while(!q.empty()) { Node node = q.top(); q.pop(); int i = node.i, t = adj[i].size(); if(dist[i][1] == node.t) { for(int j = 0; j < t; j++) { ll nex = adj[i][j], time = dist[i][1] + len[i][j]; if(time < dist[nex][0]) swap(time, dist[nex][0]); if(time < dist[nex][1]) { swap(time, dist[nex][1]); q.push({nex, dist[nex][1]}); } } } } } int travel_plan(int n1, int m1, int R[][2], int L[], int K, int P[]) { n = n1, m = m1; for(int i = 0; i < m; i++) { len[R[i][0]].push_back(L[i]); len[R[i][1]].push_back(L[i]); adj[R[i][0]].push_back(R[i][1]); adj[R[i][1]].push_back(R[i][0]); } for(int i = 0; i < n; i++) dist[i][0] = dist[i][1] = INF; for(int i = 0; i < K; i++) dist[P[i]][0] = dist[P[i]][1] = 0; for(int i = 0; i < K; i++) q.push({P[i], 0}); Dijkstra(); return dist[0][1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...