PII = std::pair<int, int>;
8intprim(
intx,
conststd::vector<std::vector<PII> > &
graph) {
10std::priority_queue<PII, std::vector<PII>, std::greater<PII> > Q;
11std::vector<bool> marked(
graph.size(),
false);
14Q.push(std::make_pair(0, x));
21 if(marked[x] ==
true) {
24minimum_cost += p.first;
26 for(
constPII &neighbor :
graph[x]) {
27 inty = neighbor.second;
28 if(marked[y] ==
false) {
37 intnodes = 0, edges = 0;
38std::cin >> nodes >> edges;
39 if(nodes == 0 || edges == 0) {
43std::vector<std::vector<PII> >
graph(nodes);
46 for(
inti = 0; i < edges; ++i) {
47 intx = 0, y = 0, weight = 0;
48std::cin >> x >> y >> weight;
49 graph[x].push_back(std::make_pair(weight, y));
50 graph[y].push_back(std::make_pair(weight, x));
54 intminimum_cost = prim(1,
graph);
55std::cout << minimum_cost << std::endl;
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4