fork download
  1. /*******************************************
  2.  * Vijay Sharma
  3.  * ****************************************/
  4.  
  5.  
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. #define PII pair<int,int>
  9. #define PF push_front
  10. #define MK make_pair
  11. #define ll long long
  12.  
  13. /*list<PII > *graph;
  14.  
  15. void addEdge(int src,int des,int wt){
  16. PII x;
  17. x.first = des;
  18. x.second = wt;
  19. graph[src].PF(MK(des,wt));
  20. x.first = src;
  21. x.second = wt;
  22. graph[des].PF(MK(src,wt));
  23. }*/
  24.  
  25. vector<pair<int,pair<int,int> > > v;
  26. int *A;
  27.  
  28. void makeSet(int v){
  29. A = new int[v+1];
  30. for(int i=0;i<=v;i++){
  31. A[i]=i;
  32. }
  33. }
  34.  
  35. int root(int x){
  36. while(x!=A[x]){
  37. A[x]=A[A[x]];
  38. x=A[x];
  39. }
  40. return x;
  41. }
  42.  
  43. void union(int x,int y){
  44. x = root(x);
  45. y = root(y);
  46. A[x]=A[y];
  47. }
  48.  
  49. int kruskal(int ed){
  50. PII x;
  51. int minWeight=0;
  52.  
  53. for(int i=0;i!=ed;i++){
  54. x = v[i].second;
  55. if(root(x.first)!=root(x.second)){
  56. minWeight += v[i].first;
  57. union(x.first,x.second);
  58. }
  59. }
  60. return minWeight;
  61. }
  62.  
  63. int main(){
  64. int v,e;
  65. cin>>v>>e;
  66. makeSet(v);
  67. //graph = new lsit<PII >[v+1];
  68.  
  69. int x,y,wt;
  70. for(int i=0;i<e;i++){
  71. cin>>x>>y>>wt;
  72. //addEdge(x,y,wt);
  73. v.push_back(MK(wt,MK(x,y)));
  74. }
  75. sort(v.begin(),v.end());
  76.  
  77. int spanWeight=kruskal(e);
  78. cout<<spanWeight<<'\n';
  79.  
  80. return 0;
  81. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:43:11: error: expected identifier before '(' token
 void union(int x,int y){
           ^
prog.cpp:43:12: error: expected unqualified-id before 'int'
 void union(int x,int y){
            ^
prog.cpp:43:12: error: expected ')' before 'int'
prog.cpp: In function 'int kruskal(int)':
prog.cpp:57:4: error: expected primary-expression before 'union'
    union(x.first,x.second);
    ^
prog.cpp: In function 'int main()':
prog.cpp:73:5: error: request for member 'push_back' in 'v', which is of non-class type 'int'
   v.push_back(MK(wt,MK(x,y)));
     ^
prog.cpp:75:9: error: request for member 'begin' in 'v', which is of non-class type 'int'
  sort(v.begin(),v.end());
         ^
prog.cpp:75:19: error: request for member 'end' in 'v', which is of non-class type 'int'
  sort(v.begin(),v.end());
                   ^
stdout
Standard output is empty