Submission #667098

#TimeUsernameProblemLanguageResultExecution timeMemory
667098ansgarCrocodile's Underground City (IOI11_crocodile)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define vvi vector<vi> #define pii pair<int,int> #define vpii vector<pii> #define vvpii vector<vpii> #define vb vector<bool> #define vc vector<char> #define vvc vector<vc> #define vvb vector<vb> #define si set<int> #define mii map<int,int> const int mod=1e9+7; const int N=2e5+1; const int LN=INT_MAX/10; struct com{ bool operator()(pair<pii,int>& a,pair<pii,int>& b){ return a.second>b.second; } }; struct co{ bool operator()(pii& a,pii& b){ return a.second>b.second; } }; int travel_plan(int n,int m,int R[][2],int L[],int k,int P[]){ vvpii G(n); for(int i=0;i<m;i++){ G[R[i][0]].push_back({R[i][1],L[i]}); G[R[i][1]].push_back({R[i][0],L[i]}); } priority_queue<pair<pii,int>,vector<pair<pii,int>>,com> Q; for(int i=0;i<k;i++){ Q.push({{P[i],P[i]},0}); } vi bloq(n,LN); while(Q.size()){ int u=Q.top().first.first; int p=Q.top().first.second; int wu=Q.top().second; Q.pop(); if(bloq[u]!=LN)continue; bloq[u]=p; for(auto x : G[u]){ int v=x.first; int wv=x.second; if(bloq[v]==LN)Q.push({{v,u},wu+wv}); } } vi dist(n,LN); priority_queue<pii,vpii,co> Q2; Q2.push({0,0}); while(Q2.size()){ int u=Q2.top().first; int wu=Q2.top().second; Q2.pop(); if(dist[u]!=LN)continue; dist[u]=wu; for(auto x : G[u]){ int v=x.first; int wv=x.second; if(bloq[u]==v)continue; if(dist[v]==LN)Q2.push({v,wu+wv}); } } int sol=LN; for(int i=0;i<k;i++){ sol=min(sol,dist[P[i]]); } if(sol==LN)return -1; return sol; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...