-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreuniao.cpp
77 lines (65 loc) · 1.54 KB
/
reuniao.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// source:
// https://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <string.h> // memset
#include <algorithm> // lower_bound
#include <iomanip>
using namespace std;
#define fs first
#define sd second
#define pb push_back
#define vii vector<int>
#define pii pair<int, int>
#define MAXN 1200
const int INF = 0x3f3f3f3f;
// Matriz de adjacencia
int grafo[MAXN][MAXN];
/**
* A^(k) = min { A^(k-1)[i][j], A^(k-1)[i][k] + A^(k-1)[k][j] }
*/
void floydWarshall(int n) {
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
grafo[i][j] = min(grafo[i][j], grafo[i][k] + grafo[k][j]);
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
grafo[i][j] = INF;
if(i == j)
grafo[i][j] = 0;
}
}
int a, b, c;
for(int i = 0; i < m; ++i) {
cin >> a >> b >> c;
grafo[a][b] = c;
grafo[b][a] = c;
}
floydWarshall(n);
int ans = INF, minLinha;
for (int i = 0; i < n; ++i) {
minLinha = 0;
for (int j = 0; j < n; ++j) {
if(grafo[i][j] != INF) {
minLinha = max(minLinha, grafo[i][j]);
}
}
ans = min (ans, minLinha);
}
cout << ans << endl;
return 0;
}