이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |