제출 #849121

#제출 시각아이디문제언어결과실행 시간메모리
849121adhityamv사이버랜드 (APIO23_cyberland)C++17
44 / 100
32 ms10184 KiB
#include <bits/stdc++.h> using namespace std; const int N=100000; vector<pair<int,double>> edges[N]; bool visited[N]={}; double ans[N]; void dfs(int u,int h){ for(auto v:edges[u]){ if(v.first==h) continue; if(!visited[v.first]){ visited[v.first]=true; dfs(v.first, h); } } } double solve(int n,int m,int k,int h,vector<int> x,vector<int> y,vector<int> c,vector<int> a){ for(int i=0;i<n;i++) ans[i]=-1; for(int i=0;i<m;i++){ edges[x[i]].push_back(make_pair(y[i],(double) c[i])); edges[y[i]].push_back(make_pair(x[i],(double) c[i])); } priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> pq; ans[0]=0; visited[0]=true; dfs(0,h); pq.push(make_pair(0,0)); for(int i=0;i<n;i++){ if(a[i]==0 && visited[i]){ ans[i]=0; pq.push(make_pair(0,i)); } } while(!pq.empty()){ auto u=pq.top(); pq.pop(); if(u.second==h) continue; if(u.first!=ans[u.second]) continue; for(auto v:edges[u.second]){ if(ans[v.first]==-1 || ans[v.first]>u.first+v.second){ ans[v.first]=u.first+v.second; pq.push(make_pair(ans[v.first],v.first)); } } } double fans=ans[h]; for(int i=0;i<n;i++){ edges[i].clear(); visited[i]=false; ans[i]=0; } return fans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...