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 <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001001001
#define MOD 1000000007
bool visited[100001],cut[100001];
vector<pair<int,int>>adj[100001];
ll dis[100001];
priority_queue<pair<ll,ll>>pq; //-dis, node
void dijkstra(int K, int P[]){
for (int i=0;i<K;i++){
cut[P[i]]=true;
dis[P[i]]=0;
pq.push({0,P[i]});
}
while (!pq.empty()){
ll d=-pq.top().first;
int cur=pq.top().second;
pq.pop();
if (!cut[cur]){
cut[cur]=true;
continue;
}
if (visited[cur])
continue;
visited[cur]=true;
dis[cur]=d;
for (auto x:adj[cur]){
if (!visited[x.first])
pq.push({-(d+x.second),x.first});
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
for (int i=0;i<M;i++){
adj[R[i][0]].push_back({R[i][1],L[i]});
adj[R[i][1]].push_back({R[i][0],L[i]});
}
for (int i=0;i<N;i++)
dis[i]=INF;
dijkstra(K,P);
return dis[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... |