Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<queue>
- using namespace std;
- int main(){
- int v;
- cin >> v;
- vector<vector<pair<int,int>>> g(v);
- for(int i=0; i<v; i++){
- int times,to,edge;
- cin >> times;
- for(int j=0; j<times; j++){
- cin >> to >> edge;
- g[i].push_back(make_pair(to,edge));
- }
- }
- int d[v];
- for(int i=0; i<v; i++) d[i] = 40000;
- priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
- pq.push(make_pair(0,0));
- while(!pq.empty()){
- pair<int,int> f = pq.top();
- pq.pop();
- if(f.first < d[f.second]) d[f.second] = f.first;
- for(auto it : g[f.second]) pq.push(make_pair(f.first+it.second,it.first));
- }
- for(int i=0; i<v; i++){
- cout << d[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement