-
algospot - drunkenAlgorithm/알고스팟 2020. 1. 29. 16:5612345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758//algospot - drunken#include <iostream>#include <vector>#include <algorithm>using namespace std;#define INF 1000000int V, E;vector<vector<int>> adj, ans;vector<pair<int, int>> weight;void mkg(){cin >> V >> E;ans = adj = vector<vector<int>>(V+1, vector<int>(V+1, INF));weight = vector<pair<int, int>>(V);int x, y, r;for(int i = 0; i<V; ++i){cin >> x;weight[i].first = x;weight[i].second = i+1;ans[i+1][i+1] = adj[i+1][i+1] = 0;}sort(weight.begin(), weight.end());for(int i = 0; i<E; ++i){cin >> x >> y >> r;ans[x][y] = ans[y][x] = adj[x][y] = adj[y][x] = r;}for(int k = 0; k<V; ++k){int w = weight[k].second;int c = weight[k].first;for(int i = 1; i<=V; ++i)for(int j = 1; j<=V; ++j)if(adj[i][j] > adj[i][w] + adj[w][j]){adj[i][j] = adj[i][w] + adj[w][j];ans[i][j] = min(ans[i][j], adj[i][w] + adj[w][j] + c);}}}int main(){mkg();int C; cin >> C;int st, ed;for(int tn = 0; tn<C; ++tn){cin >> st >> ed;cout << ans[st][ed] << "\n";}}
cs https://algospot.com/judge/problem/read/DRUNKEN
algospot.com :: DRUNKEN
Drunken Driving 문제 정보 문제 As the holiday season approaches, the number of incidents caused by Driving While Intoxicated (known as DWI) increases rapidly. To prevent this, the city of Seoul has proclaimed a war against drunken driving. Every day, the city wi
algospot.com
플로이드와샬 알고리즘 실행 중간에 경유점의 weight를 고려합니다.
'Algorithm > 알고스팟' 카테고리의 다른 글
algospot - lan (0) 2020.01.31 algospot - promises (0) 2020.01.29 algospot - nthlon (0) 2020.01.20 algospot - firetrucks (0) 2020.01.20 algospot - clocksync (0) 2020.01.20