-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10652.cpp
63 lines (53 loc) · 1.04 KB
/
10652.cpp
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int>pi;
int b, e, p, n, m;
ll ans = 9987654321;
vector<int>adj[40005];
int visited[3][40005];
void bfs(int st) {
queue<pi>q;
q.push({ st, 1 });
if (st == n) {
st = 0;
visited[0][n] = 0;
}
else visited[st][st] = 0;
while (!q.empty()) {
int x = q.front().first;
int dist = q.front().second;
q.pop();
for (int i = 0; i < adj[x].size(); i++)
{
int nx = adj[x][i];
if (visited[st][nx] >= 0) continue;
visited[st][nx] = dist;
q.push({ nx, dist + 1 });
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> b >> e >> p >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 0; i < 3; i++)
for (int j = 1; j <= n; j++)
visited[i][j] = -1;
bfs(1); bfs(2);
bfs(n);
for (int i = 1; i <= n; i++)
{
ans = min(ans, (ll)(visited[1][i] * b) + (ll)(visited[2][i] * e)
+ (ll)(visited[0][i] * p));
}
cout << ans;
}