-
algospot - routingAlgorithm/알고스팟 2020. 1. 15. 06:56123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566//algospot - routing#include <iostream>#include <vector>#include <queue>using namespace std;int N, M;vector<vector<pair<int, double>>> adj;vector<double> c;void init(){cin >> N >> M;adj = vector<vector<pair<int, double>>>(N);c = vector<double>(N, 0);int x, y;double z;for(int i = 0; i<M; i++){cin >> x >> y >> z;adj[x].push_back(make_pair(y, z));adj[y].push_back(make_pair(x, z));}}double dijkstra(){priority_queue<pair<double, int>> pq;pq.push(make_pair(-1, 0));int here; double cost;int there; double mul;while(true){here = pq.top().second; cost = pq.top().first;if(here == N-1)return -cost;pq.pop();if(!c[here] || cost <= c[here]){for(int i = 0; i<adj[here].size(); ++i){there = adj[here][i].first;mul = adj[here][i].second;if(!c[there] || cost*mul > c[there]){c[there] = cost*mul;pq.push(make_pair(cost*mul, there));}}}}}int main(){ios_base::sync_with_stdio(0); cin.tie(0);int C; cin >> C;for(int t_num = 0; t_num < C; ++t_num){init();cout.setf(ios::fixed);cout.precision(10);cout << dijkstra() << "\n";}}
cs https://algospot.com/judge/problem/read/ROUTING
algospot.com :: ROUTING
신호 라우팅 문제 정보 문제 위 그림은 여러 개의 컴퓨터들과 각 컴퓨터들을 잇는 회선을 나타냅니다. 각 회선들은 각각 품질이 다르며, 각 회선을 지날 때마다 신호에 있던 노이즈가 증폭될 수 있습니다. 각 회선에 쓰여 있는 글자는 해당 회선을 지날 때 노이즈가 몇 배 증폭되는가를 보여줍니다. 특정 컴퓨터에서 다른 컴퓨터로 메시지를 보내고 싶습니다. 이 때 노이즈의 증폭을 최소화하는 프로그램을 작성하세요. 입력 입력의 첫 줄에는 테스트 케이스의 수 C (<=
algospot.com
기본적인 다익스트라 문제
'Algorithm > 알고스팟' 카테고리의 다른 글
algospot - picnic (0) 2020.01.17 algospot - boardcover (0) 2020.01.17 algospot - sortgame (0) 2020.01.10 algospot - wordchain (0) 2020.01.10 algospot - dictionary (0) 2020.01.10