Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 15d224f

Browse files
changes
1 parent ffb2626 commit 15d224f

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

‎Greedy/Dijkstra.cpp‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,28 @@ ll solve()
9292
vector<vector<pair<ll,ll>>> graph(vertex+1,vector<ll>());
9393
vector<ll> shortes_path(vertex+1,INF);
9494
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});
9999
}
100100

101101
// finding shortest distance from 1
102102
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+
}
111111

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+
}
117117
return 0;
118118
}
119119

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /