-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1205.cpp
57 lines (57 loc) · 1.7 KB
/
1205.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
// Ivan Carvalho
// Solution to https://www.beecrowd.com.br/judge/problems/view/1205
#include <cmath>
#include <cstdio>
#include <queue>
#include <vector>
#define MAXN 1001
#define MP make_pair
using namespace std;
typedef pair<int, int> ii;
vector<int> grafo[MAXN];
int processado[MAXN], soldados[MAXN], n, m, k, a, ini, fim, possivel;
double probabilidade;
int main() {
while (scanf("%d %d %d %lf", &n, &m, &k, &probabilidade) != EOF) {
possivel = 0;
for (int i = 1; i <= n; i++) {
grafo[i].clear();
processado[i] = 0;
soldados[i] = 0;
}
while (m--) {
int u, v;
scanf("%d %d", &u, &v);
grafo[u].push_back(v);
grafo[v].push_back(u);
}
priority_queue<ii> Dijkstra;
scanf("%d", &a);
while (a--) {
int davez;
scanf("%d", &davez);
soldados[davez]++;
}
scanf("%d %d", &ini, &fim);
Dijkstra.push(MP(k - soldados[ini], ini));
while (!Dijkstra.empty()) {
ii davez = Dijkstra.top();
Dijkstra.pop();
int balas = davez.first, atual = davez.second;
if (balas < 0) continue;
if (atual == fim) {
possivel = 1;
printf("%.3lf\n", pow(probabilidade, k - balas));
break;
}
if (processado[atual]) continue;
processado[atual] = 1;
for (int i = 0; i < grafo[atual].size(); i++) {
int proximo = grafo[atual][i];
Dijkstra.push(MP(balas - soldados[proximo], proximo));
}
}
if (!possivel) printf("0.000\n");
}
return 0;
}