-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1112_Mice_and_Maze.cpp
69 lines (56 loc) · 1.28 KB
/
1112_Mice_and_Maze.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
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#define INF INT_MAX / 2
using namespace std;
void floyd(vector<vector<double>> &grafo)
{
int n = grafo.size();
for (int k = 0; k < n; k++)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
grafo[i][j] = min(grafo[i][j], grafo[i][k] + grafo[k][j]);
}
}
}
}
int main()
{
int node, aresta, qtd, x, y, consultas, inicio, tempo, contador = 0;
double peso;
cin >> qtd;
cout << endl;
for (int i = 0; i < qtd; i++)
{
cin >> node;
cin >> inicio;
cin >> tempo;
cin >> aresta;
cout << endl;
vector<vector<double>> grafo(node, vector<double>(node, INF));
for (int i = 0; i < node; i++)
{
grafo[i][i] = 0;
}
for (int i = 0; i < aresta; i++)
{
cin >> x >> y >> peso;
grafo[x - 1][y - 1] = peso;
grafo[y - 1][x - 1] = peso;
}
floyd(grafo);
for (int i = 0; i < grafo.size(); i++)
{
if (grafo[inicio - 1][i] <= tempo)
{
contador++;
}
}
cout << contador;
}
return 0;
}