forked from mejibyte/live-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2425.cpp
54 lines (46 loc) · 922 Bytes
/
2425.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
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
unsigned long long g[101][101];
int main(){
int casos;
cin >> casos;
bool first = true;
while (casos--){
if (!first) cout << endl;
first = false;
int n, e, t;
cin >> n >> e >> t;
for (int i=0; i<n; ++i){
for (int j=0; j<n; ++j){
g[i][j] = INT_MAX;
}
g[i][i] = 0;
}
int m;
cin >> m;
while (m--){
int i, j, k;
cin >> i >> j >> k;
g[i-1][j-1] = k;
}
for (int k=0; k<n; ++k){
for (int i=0; i<n; ++i){
for (int j=0; j<n; ++j){
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
}
}
int r=0;
e -= 1;
for (int i=0; i<n; ++i){
r += ((g[i][e] <= t) ? 1 : 0);
/* if (g[i][e] <= t){
cout << "Adding " << i+1 << " - distancia: " << g[i][e] << endl;
}*/
}
cout << r << endl;
}
return 0;
}