제출 #567505

#제출 시각아이디문제언어결과실행 시간메모리
567505losmi247악어의 지하 도시 (IOI11_crocodile)C++14
0 / 100
2 ms2644 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+45; int n,m,k; vector <pair<int,ll>> g[N]; bool ex[N]; ll dp1[N]; void dfstr(int x,int par){ vector <ll> svi; for(auto f : g[x]){ int u = f.first; if(u == par) continue; ll w = f.second; dfstr(u,x); svi.push_back(dp1[u]+w); } if(svi.empty()) return; assert(svi.size() >= 2); sort(svi.begin(),svi.end()); dp1[x] = svi[1]; } int zadrvo(){ dfstr(1,0); return dp1[1]; } ll d1[N],d2[N]; int travel_plan(int br,int M,int R[][2],int L[],int K,int P[]){ n = br; m = M; k = K; for(int i = 0; i < m; i++){ g[R[i][0]+1].push_back({R[i][1]+1,L[i]}); g[R[i][1]+1].push_back({R[i][0]+1,L[i]}); } for(int i = 0; i < k; i++){ ex[P[i]+1] = 1; } //return zadrvo(); for(int i = 1; i <= n; i++) d1[i] = d2[i] = 7e16; priority_queue <pair<ll,int>> pq; for(int i = 1; i <= n; i++){ if(ex[i]){ pq.push({0,i}); d1[i] = d2[i] = 0; } } while(!pq.empty()){ ll d = -pq.top().first; int u = pq.top().second; pq.pop(); for(auto f : g[u]){ int v = f.first,cost = f.second; if(d+cost < d1[v]){ d2[v] = d1[v]; d1[v] = d+cost; if(d2[v] != 7e16) pq.push({-d2[v],v}); } else if(d+cost < d2[v]){ d2[v] = d+cost; if(d2[v] != 7e16) pq.push({-d2[v],v}); } } } return d2[1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...