Algorithm/알고스팟
algospot - routing
jhg0406
2020. 1. 15. 06:56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
//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
Routing
기본적인 다익스트라 문제
