이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>> > conns;
int main(){
int nodes, edges, targets;
cin >> nodes >> edges >> targets;
conns.resize(nodes);
ios_base::sync_with_stdio(0);
cin.tie(0);
vector<pair<int, int>> edgeSort;
for (int i = 0; i < edges; i++){
int a, b, c;
cin >> a >> b>> c;
a--; b--; c *= -1;
conns[a].push_back({c,b});
conns[b].push_back({c, a});
}
for (int i = 0 ; i < nodes; i++){
sort(conns[i].begin(), conns[i].end());
}
int remaining = 0;
vector<bool> needed(nodes, 0);
vector<int> trg;
for (int i = 0 ; i < targets; i++){
remaining ++;
int a;
cin >> a; a--;
needed[a] = 1;
trg.push_back(a);
}
vector<long long> best(nodes, 1000000000000000000LL);
priority_queue<pair<long long, int>> pq;
pq.push({-1000000000000000000LL,0});
while (true){
int pos, cost;
do{
pos = pq.top().second;
cost = -pq.top().first;
pq.pop();
}while(cost > best[pos]);
if (needed[pos]) remaining --;
if (remaining == 0) break;
for (int i = 0; i < conns[pos].size(); i++){
int c = max(cost, conns[pos][i].first);
if (c < best[conns[pos][i].second]){
best[conns[pos][i].second] = c;
pq.push({-c, conns[pos][i].second});
}
}
}
for (int i = 0; i < targets; i++){
cout << -best[trg[i]] << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
sightseeing.cpp: In function 'int main()':
sightseeing.cpp:47:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < conns[pos].size(); i++){
~~^~~~~~~~~~~~~~~~~~~
# | 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... |