-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloy.cpp
More file actions
46 lines (45 loc) · 842 Bytes
/
Copy pathFloy.cpp
File metadata and controls
46 lines (45 loc) · 842 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
41
42
43
44
45
46
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int,int> ii;
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = a; i >= b; --i)
#define fi first
#define se second
#define pb push_back
const int MOD = 1e9 + 7;
const int MAX = 1e3 + 5;
const int oo = 1e9;
int N, cnt = 0, b[5], visited[MAX], res = INT_MAX;
struct node{
int u, v, w;
};
int F[MAX][MAX];
void init_floy(){
FOR(i, 1, N){
FOR(j, 1, N){
if(i == j) F[i][j] = 0;
else F[i][j] = oo;
}
}
}
void floy(){
FOR(k, 1, N){
FOR(i, 1, N){
FOR(j, 1, N){
F[i][j] = min(F[i][j], F[i][k] + F[k][j]);
}
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(nullptr);
cin >> N;
FOR(i, 1, 4) cin >> b[i];
init_floy();
int u, v, w;
while(cin >> u >> v >> w){
F[u][v] = F[v][u] = w;
}
floy();
}