Submission #717483

# Submission time Handle Problem Language Result Execution time Memory
717483 2023-04-02T01:35:32 Z IamKittitat Autići (COCI22_autici) C++14
0 / 50
1000 ms 2440 KB
#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;
}

Compilation message

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
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1083 ms 2440 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Incorrect 2 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1083 ms 2440 KB Time limit exceeded
3 Halted 0 ms 0 KB -