-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnt Challenge.cpp
73 lines (54 loc) · 1.8 KB
/
Ant Challenge.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
#include <bits/stdc++.h>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#define int long
using namespace std;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
boost::no_property, boost::property<boost::edge_weight_t, int> > graph;
typedef boost::property_map<graph, boost::edge_weight_t>::type weight_map;
typedef boost::graph_traits<graph>::edge_descriptor edge_desc;
typedef boost::graph_traits<graph>::vertex_descriptor vertex_desc;
int dijkstra_dist(const graph &G, int s, int t) {
int n = boost::num_vertices(G);
std::vector<int> dist_map(n);
boost::dijkstra_shortest_paths(G, s,
boost::distance_map(boost::make_iterator_property_map(
dist_map.begin(), boost::get(boost::vertex_index, G))));
return dist_map[t];
}
void solve() {
int n,e,s,a,b;
cin >> n >> e >> s >> a >> b;
vector<graph> networks(s,graph(n));
for(int i = 0; i < e;i++) {
int from,to;
cin >> from >> to;
for(int j = 0; j < s;j++) {
int w;
cin >> w;
boost::add_edge(from,to,w,networks[j]);
}
}
int tmp;
for(int i = 0; i < s; i++) cin >> tmp;
graph final(n);
for(auto net : networks) {
std::vector<edge_desc> mst;
boost::kruskal_minimum_spanning_tree(net, std::back_inserter(mst));
auto weights = boost::get(boost::edge_weight,net);
for (std::vector<edge_desc>::iterator it = mst.begin(); it != mst.end(); ++it) {
boost::add_edge(boost::source(*it, net),boost::target(*it, net),weights[*it],final);
}
}
cout << dijkstra_dist(final,a,b) << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}