이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> g(n);
for(int i= 0;i<n;i++) cin >> g[i];
vector<int> dist(n,INT32_MAX);
vector<bool> inMST(n,false);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
dist[0] = 0;
int ans = 0;
pq.push({dist[0],0});
while(!pq.empty()){
pair<int,int> t = pq.top();
pq.pop();
int w = t.first, v = t.second;
if(!inMST[v]){
ans += dist[v];
inMST[v] = true;
for(int i = 0;i<n;i++){
if(i != v && g[i] + g[v] < dist[i]){
dist[i] = g[i] + g[v];
pq.push({dist[i],i});
}
}
}
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:21:13: warning: unused variable 'w' [-Wunused-variable]
21 | int w = t.first, v = t.second;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |