-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaze and mice
More file actions
59 lines (57 loc) · 1.1 KB
/
Maze and mice
File metadata and controls
59 lines (57 loc) · 1.1 KB
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
#include<iostream>
#include<queue>
#include<vector>
#include<functional>
#include<fstream>
using namespace std;
int n;
vector<pair<int, int> >adj_list[105];
vector<int>dijkstra(int node)
{
vector<int>sp(n, -1);
priority_queue < pair<int, int>, vector<pair<int, int> >, greater<pair<int,int> > > q;
q.push(make_pair(0, node));
while (!q.empty())
{
int parent = q.top().second;
int cost = q.top().first;
q.pop();
if (sp[parent] != -1)
continue;
sp[parent] = cost;
for (int i = 0; i < adj_list[parent].size(); i++)
{
int child = adj_list[parent][i].second;
if (sp[child] == -1)
q.push(make_pair(cost+adj_list[parent][i].first, child));
}
}
return sp;
}
int main()
{
int N;
cin >> N;
while (N--)
{
int e, t;
long long m;
cin >> n >> e >> t >> m;
for (int i =0;i < n;i++)
adj_list[i].clear();
for (int i = 0; i < m; i++)
{
int x, y, w;
cin >> x >> y >> w;
adj_list[x - 1].push_back(make_pair(w, y - 1));
}
int answer = 0;
vector<int>sp = dijkstra(e-1);
for (int i = 0;i < n;i++)
{
if (sp[i] >= t)
answer++;
}
cout << answer << endl<<endl;
}
}