|
| 1 | +#include <iostream> |
| 2 | +#include <cstdio> |
| 3 | +#include <vector> |
| 4 | +#include <map> |
| 5 | +#include <queue> |
| 6 | +#include <algorithm> |
| 7 | + |
| 8 | +using namespace std; |
| 9 | + |
| 10 | +typedef pair <int,int> pii; |
| 11 | +typedef vector <pii> vpii; |
| 12 | + |
| 13 | +vpii graph[100]; |
| 14 | +int id[100]; |
| 15 | +int sz[100]; |
| 16 | +void init(int n){ |
| 17 | + for(int i = 0 ; i < n ; i++) |
| 18 | + { |
| 19 | + id[i] = i; |
| 20 | + sz[i] = 1; |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +int find(int p){ |
| 25 | + while(p!=id[p]){ |
| 26 | + p = id[p]; |
| 27 | + } |
| 28 | + return p; |
| 29 | +} |
| 30 | + |
| 31 | +bool conncted(int p , int q){ |
| 32 | + return (find(p) == find(q)); |
| 33 | +} |
| 34 | + |
| 35 | +void join(int p , int q){ |
| 36 | + int proot = find(p); |
| 37 | + int qroot = find(q); |
| 38 | + id[proot] = qroot; |
| 39 | +} |
| 40 | + |
| 41 | +struct Edge{ |
| 42 | + int weight; |
| 43 | + int either; |
| 44 | + int other; |
| 45 | +}; |
| 46 | +struct comparator{ |
| 47 | + bool operator()(const Edge &a, const Edge &b){ |
| 48 | + return (a.weight > b.weight); |
| 49 | + } |
| 50 | +}; |
| 51 | +int main(){ |
| 52 | + priority_queue<Edge,vector<Edge>,comparator> Q; |
| 53 | + //sample graph |
| 54 | + Edge edge[8]; |
| 55 | + graph[0].push_back(pii(26,2));graph[0].push_back(pii(38,4));graph[0].push_back(pii(58,6));graph[0].push_back(pii(16,7)); |
| 56 | + graph[1].push_back(pii(36,2));graph[1].push_back(pii(29,3));graph[1].push_back(pii(32,5));graph[1].push_back(pii(19,7)); |
| 57 | + graph[2].push_back(pii(26,0));graph[2].push_back(pii(36,1));graph[2].push_back(pii(17,3));graph[2].push_back(pii(40,6));graph[2].push_back(pii(34,7)); |
| 58 | + graph[3].push_back(pii(29,1));graph[3].push_back(pii(17,2));graph[3].push_back(pii(52,6)); |
| 59 | + graph[4].push_back(pii(38,0));graph[4].push_back(pii(35,5));graph[4].push_back(pii(93,6));graph[4].push_back(pii(37,7)); |
| 60 | + graph[5].push_back(pii(32,1));graph[5].push_back(pii(35,4));graph[5].push_back(pii(28,7)); |
| 61 | + graph[6].push_back(pii(58,0));graph[6].push_back(pii(40,2));graph[6].push_back(pii(52,3));graph[6].push_back(pii(93,4)); |
| 62 | + graph[7].push_back(pii(16,0));graph[7].push_back(pii(19,1));graph[7].push_back(pii(34,2));graph[7].push_back(pii(37,4));graph[7].push_back(pii(28,5)); |
| 63 | + |
| 64 | + //sample graph ends |
| 65 | + edge[0].either = 0; edge[0].other = 2; edge[0].weight = 26; edge[0].either = 0; edge[0].other = 4; edge[0].weight = 38; |
| 66 | + edge[0].either = 0; edge[0].other = 6; edge[0].weight = 58; edge[0].either = 0; edge[0].other = 7; edge[0].weight = 16; |
| 67 | + |
| 68 | + |
| 69 | + Q.push() |
| 70 | + return 0; |
| 71 | +} |
0 commit comments