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>
using namespace std;
#define beegspeed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pi pair<int,int>
template<typename T>
void print(T t){
cout<<t;
exit(0);
}
vector<pi> adjlist[500007];
signed main(){
beegspeed
int n, edges, queries; cin>>n>>edges>>queries;
for(int i = 0; i < edges; i++){
int origin, dest, weight; cin>>origin>>dest>>weight;
adjlist[origin].push_back({dest,weight});
adjlist[dest].push_back({origin,weight});
}
priority_queue<pi> pq;
pq.push({1000000,1});
int dist[500007];
memset(dist, -1, sizeof dist);
dist[1] = 1000000;
while(!pq.empty()){
pi edge = pq.top();
pq.pop();
if(edge.first != dist[edge.second]) continue;
for(auto itr: adjlist[edge.second]){
if(dist[itr.first] == -1 or dist[itr.first] < min(edge.first, itr.second)){
dist[itr.first] = min(edge.first, itr.second);
pq.push({dist[itr.first], itr.first});
}
}
}
for(int i = 0; i < queries; i++){
int query; cin>>query;
cout<<dist[query]<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |