@@ -92,28 +92,28 @@ ll solve()
92
92
vector<vector<pair<ll,ll>>> graph (vertex+1 ,vector<ll>());
93
93
vector<ll> shortes_path (vertex+1 ,INF);
94
94
for (ll i=1 ;i<=edges;i++){
95
- ll u,v,weight;
96
- cin>>u>>v>>weight;
97
- graph[u].pb ({v,weight});
98
- graph[v].pb ({u,weight});
95
+ ll u,v,weight;
96
+ cin>>u>>v>>weight;
97
+ graph[u].pb ({v,weight});
98
+ graph[v].pb ({u,weight});
99
99
}
100
100
101
101
// finding shortest distance from 1
102
102
shortes_path[1 ]=0 ;
103
- for (ll i=1 ;i<=vertex;i++){
104
- ll min_vertex=1 ,mini=INF;
105
- for (ll j=1 ;j<=vertex;j++){
106
- if (shortes_path[j]<mini){
107
- mini=shortes_path[j];
108
- min_vertex=j;
109
- }
110
- }
103
+ for (ll i=1 ;i<=vertex;i++){
104
+ ll min_vertex=1 ,mini=INF;
105
+ for (ll j=1 ;j<=vertex;j++){
106
+ if (check[j]== false && shortes_path[j]<mini){
107
+ mini=shortes_path[j];
108
+ min_vertex=j;
109
+ }
110
+ }
111
111
112
- check[min_vertex]=true ;
113
- for (auto edges:graph[min_vertex]){
114
- shortes_path[edges]=min (shortes_path[edges.ff ],shortes_path[min_vertex]+edges.ss );
115
- }
116
- }
112
+ check[min_vertex]=true ;
113
+ for (auto edges:graph[min_vertex]){
114
+ shortes_path[edges]=min (shortes_path[edges.ff ],shortes_path[min_vertex]+edges.ss );
115
+ }
116
+ }
117
117
return 0 ;
118
118
}
119
119
0 commit comments