This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
vector<pair<int,int>> adj[100000];
int visited[100000]={0};
int dp[100000]={0};
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
for(int i=0;i<K;i++)visited[P[i]]=2;
priority_queue<pair<int,int>> pq;
for(int i=0;i<M;i++){
int v=R[i][0],w=R[i][1];
if(!(visited[v]==2&&visited[w]==2)){
if(!(visited[v]==2))swap(v,w);
if(visited[v])pq.push({-L[i],w});
}
adj[R[i][0]].push_back({R[i][1],L[i]});
adj[R[i][1]].push_back({R[i][0],L[i]});
}
while(!pq.empty()){
int d = -pq.top().first, v = pq.top().second;
// cout << "s" << v << ' ' << d << '\n';
pq.pop();
if(visited[v]==2)continue;
else if(visited[v]==1){
visited[v]=2;
dp[v]=d;
for(pair<int,int> _ : adj[v]){
int w=_.first, t=_.second;
pq.push({-(t+d),w});
// cout << "a" << w << ' ' << -(t+d) << '\n';
}
}else{
visited[v]=1;
}
}
// cout << pq.top().first;
// for(int i=0;i<n;i++)cout << dp[i] << ' ';
// cout << '\n';
return dp[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |