Submission #717483

#TimeUsernameProblemLanguageResultExecution timeMemory
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; }

Compilation message (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...