Submission #258855

#TimeUsernameProblemLanguageResultExecution timeMemory
258855HeheheCrocodile's Underground City (IOI11_crocodile)C++14
100 / 100
805 ms46832 KiB
#include<bits/stdc++.h> //:3 using namespace std; typedef long long ll; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define pi pair<int, int> #define sz(x) (int)((x).size()) //#define int long long #include "crocodile.h" const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const ll inf = 2e9; const ll mod = 1e9 + 7; const int N = 2e6 + 11; const ll INF64 = 3e18 + 1; const double eps = 1e-14; const double PI = acos(-1); //ifstream in(".in"); //ofstream out(".out"); int travel_plan(int n,int m,int r[][2],int l[],int k,int p[]){ vector<pi>v[n + 5]; for(int i = 0; i <= n; i++)v[i].clear(); for(int i = 0; i < m; i++){ v[r[i][0]].push_back({r[i][1], l[i]}); v[r[i][1]].push_back({r[i][0], l[i]}); } priority_queue<pi, vector<pi>, greater<pi>>q; pi dist[n + 5]; for(int i = 0; i < n; i++){ dist[i] = {INT_MAX, INT_MAX}; } for(int i = 0; i < k; i++){ q.push({0, p[i]}); dist[p[i]] = {0, 0}; } //dijkstra while(!q.empty()){ int x = q.top().ff, y = q.top().ss; q.pop(); if(x > dist[y].ss)continue; for(auto it : v[y]){ int prev = dist[it.ff].ss; //prev cost int w = it.ss; int nw = w + x; //new cost if(nw < dist[it.ff].ff){ dist[it.ff].ss = dist[it.ff].ff; dist[it.ff].ff = nw; }else if(nw < dist[it.ff].ss){ dist[it.ff].ss = nw; } if(dist[it.ff].ss < prev){//if found a better way q.push({dist[it.ff].ss, it.ff}); } } } return dist[0].ss; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...