# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
984084 | Rafiullah | Cyberland (APIO23_cyberland) | C++17 | 0 ms | 0 KiB |
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 "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
int n ,m , k,h;cin>>n>>m>>k>>h;
map<int,vector<int>> graph;
map<pair<int,int>,int> weight;
int A[n];
int dist[n];
for(int i = 0 ;i <n ;i ++){
dist[i] = 1e9;
cin>>A[i];
}
for(int i = 0 ;i<m ;i ++){
int a ,b,c;cin>>a>>b>>c;
weight[{min(a,b),max(a,b)}] = c;
graph[a].push_back(b);
graph[b].push_back(a);
}
priority_queue<pair<int,int>> pq;
dist[0]=0;
pq.push({0,0});
while(pq.size()>0){
int node = pq.top().second;
pq.pop();
// cout<<graph[node].size()<<endl;
for(int child:graph[node]){
int W = weight[{min(node,child),max(node,child)}];
// cout<<node<<" "<<child<<" "<<W<<endl;
if(dist[node]+W<dist[child]){
dist[child] = dist[node]+W;
pq.push({-dist[child],child});
}
}
}
if(dist[h] == 1e9)dist[h] = -1;
return dist[h];
}