-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1334.txt
More file actions
43 lines (37 loc) · 1.05 KB
/
1334.txt
File metadata and controls
43 lines (37 loc) · 1.05 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
class Solution {
public:
int findTheCity(int n, vector<vector<int>>& edges, int distanceThreshold) {
vector<vector<int>>dp(n,vector<int>(n,1000000));
for(vector<int>&edge:edges){
int v1=edge[0],v2=edge[1],w=edge[2];
dp[v1][v2]=w;
dp[v2][v1]=w;
}
for(int i=0;i<n;i++){
dp[i][i]=0;
}
for(int k=0;k<n;k++){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(dp[i][k]+dp[k][j]<dp[i][j]){
dp[i][j]=dp[i][k]+dp[k][j];
}
}
}
}
int res=-1;
int mx=INT_MAX;
for(int i=0;i<dp.size();i++){
int cnt=0;
for(int j=0;j<dp[0].size();j++){
if(dp[i][j]<=distanceThreshold)cnt++;
}
if(mx>=cnt){
mx=cnt;
res=i;
}
cout<<cnt<<endl;
}
return res;
}
};