-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhacker_v2.cpp
More file actions
108 lines (66 loc) · 1.81 KB
/
Copy pathhacker_v2.cpp
File metadata and controls
108 lines (66 loc) · 1.81 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Example program
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
#include <utility>
using namespace std;
vector<pair <int, int> > prim( vector<vector<pair<int, int> > > ady, int N){
pair<int, int> init = make_pair(-1, -1);
vector<pair<int, int> > arbol(N, init);
vector<int> visitado(N, 0);
//Esta parte de mierda estaria rompiendo todo, quiero una estructura de datos que sea < <peso12, nodo1>, nodo2> y ordenar por peso.
priority_queue < pair<pair<int,int> , int>, vector<pair<pair<int,int> , int> >, less<pair<pair<int,int> , int> >() > cola;
arbol[0].first = -1;
arbol[0].second = 0;
visitado[0] = 1;
for (int i = 0; i < ady.size(); i++) {
cola.push(make_pair(ady[0][i], 0));
}
while(!cola.empty()){
int current = cola.top().first.second;
if (!visitado[current]) {
arbol[current].second = cola.top().second;
arbol[current].first = cola.top().first.first;
visitado[current] = 1;
for (int j = 0; j < ady[current].size(); j++){
cola.push( make_pair(ady[current][j], j) );
}
}
cola.pop();
}
return arbol;
}
void maximoPeso(int S, int T, vector<pair<int, int> > arbol){
int maximo;
while(arbol[S].first != arbol[T].first){
maximo = max(arbol[S].second, arbol[T].second);
S = arbol[S].first;
T = arbol[T].first;
}
cout << maximo << ' ';
return;
}
int main(){
int C,L,H;
while (cin >> C >> L >> H){
if (C == -1) return 0;
vector<vector<pair <int, int> > > ady;
ady.resize(C);
for (int i = 0; i < L; i++){
int A, B, V;
cin >> A >> B >> V;
ady[A].push_back(make_pair(V, B));
ady[B].push_back(make_pair(V, A));
}
vector<pair<int, int> > mst(prim(ady, C));
for (int i = 0; i < H; i++){
int S, T;
cin >> S >> T;
maximoPeso(S, T, mst);
}
cout << endl;
}
return 0;
}