-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10282.cpp
More file actions
56 lines (56 loc) · 1.21 KB
/
10282.cpp
File metadata and controls
56 lines (56 loc) · 1.21 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
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
vector<pair<int,int>>vec[10001];
int dist[10001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin>>T;
while(T--)
{
int n,d,c;
cin>>n>>d>>c;
int a,b,s;
for(int i=1;i<=n;i++)
dist[i]=INF;
for(int i=1;i<=n;i++)
vec[i].clear();
for(int i=0;i<d;i++)
{
cin>>a>>b>>s;
vec[b].push_back({a,s});
}
queue<int>q;
dist[c]=0;
q.push(c);
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=0;i<vec[x].size();i++)
{
if(dist[vec[x][i].first]>dist[x]+vec[x][i].second){
dist[vec[x][i].first]=dist[x]+vec[x][i].second;
q.push(vec[x][i].first);
}
}
}
int ans=0;
int cnt=0;
for(int i=1;i<=n;i++)
{
if(dist[i]!=INF)
{
cnt++;
ans=max(ans,dist[i]);
}
}
cout<<cnt<<" "<<ans<<'\n';
}
}