제출 #717483

#제출 시각아이디문제언어결과실행 시간메모리
717483IamKittitatAutići (COCI22_autici)C++14
0 / 50
1083 ms2440 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...