-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1238.cpp
More file actions
40 lines (39 loc) · 781 Bytes
/
1238.cpp
File metadata and controls
40 lines (39 loc) · 781 Bytes
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
#include<iostream>
#include<vector>
#include<algorithm>
int d[1001][1001];
#define INF 987654321
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,x,a,b,c;
cin>>n>>m>>x;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(i==j)
d[i][j]=0;
else
d[i][j]=INF;
}
for(int i=1;i<=m;i++)
{
cin>>a>>b>>c;
d[a][b]=c;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(d[i][j]>d[i][k]+d[k][j])
d[i][j]=d[i][k]+d[k][j];
}
int ans=0;
for(int i=1;i<=n;i++)
{
ans=max(ans,d[i][x]+d[x][i]);
}
cout<<ans;
}