제출 #1017887

#제출 시각아이디문제언어결과실행 시간메모리
1017887KodikCrocodile's Underground City (IOI11_crocodile)C++17
100 / 100
326 ms65672 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; #define ss second #define ff first typedef long long ll; // #define int ll int mod = 1e9+7; int travel_plan(int N, int M, int R[][2], int L[], int k, int p[]){ int n = N, m = M; vector<vector<pair<int,int>>> adj(n); for(int i = 0; i < m; ++i){ int a = R[i][0],b = R[i][1],c = L[i]; adj[a].push_back({c,b}); adj[b].push_back({c,a}); } for(int i = 0; i < n; ++i){ sort(adj[i].begin(), adj[i].end()); } priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq; vector<vector<ll>> dis(2,vector<ll>(n, 1e18)); for(int i = 0; i < k; ++i){ pq.push({0,p[i]}); dis[0][p[i]] = 0; dis[1][p[i]] = 0; } while(!pq.empty()){ pair<int,int> a = pq.top(); pq.pop(); if(dis[1][a.ss]!=a.ff){ continue; } for(auto &[w, nxt] : adj[a.ss]){ if(a.ff+w<dis[0][nxt]){ if(dis[0][nxt]!=dis[1][nxt]){ pq.push({dis[0][nxt], nxt}); } swap(dis[0][nxt], dis[1][nxt]); dis[0][nxt] = a.ff+w; }else if(a.ff+w<dis[1][nxt]){ dis[1][nxt] = a.ff+w; pq.push({dis[1][nxt], nxt}); } } } return dis[1][0]; } // signed main(){ // ios_base::sync_with_stdio(false); // cin.tie(NULL); // // ifstream cin ("shortcut.in"); // // ofstream cout ("shortcut.out"); // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...