fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll ;
  4. #define AC cin.sync_with_stdio(0),cin.tie(0);
  5.  
  6. int parent[10000];
  7.  
  8. struct point{
  9. ll x,y;//coords
  10. };
  11.  
  12. struct line{
  13. point a,b;//2 points
  14. ll w;//weight
  15. };
  16.  
  17. bool cmp(line a, line b){
  18. return a.w<b.w;
  19. }
  20.  
  21. int FindParent(int i){
  22. if(parent[i]==-1) return i;
  23. else return FindParent(parent[i]);
  24. }
  25. int main(){
  26. //kruskal->get all line
  27. AC
  28. ll n,x,y,ans=0;
  29. cin>>n;
  30. for(int i=0;i<n;i++) parent[i] = -1;
  31. vector<line> vec;
  32. point p[10000];
  33. line tmp;
  34. //get all lines
  35. for(int i=0;i<n;i++){
  36. cin>>x>>y;
  37. p[i].x=x;
  38. p[i].y=y;
  39. for(int j=0;j<i;j++){
  40. tmp.a=p[j];
  41. tmp.b=p[i];
  42. //index of point b must be bigger than a
  43. tmp.w=( abs(p[i].x-p[j].x) + abs(p[i].y - p[j].y));
  44. vec.push_back(tmp);
  45. }
  46. }
  47. sort(vec.begin(),vec.end(),cmp);
  48.  
  49. //kruskal
  50.  
  51. for(int i=0;i<vec.size();i++){
  52. x=FindParent(vec[i].a);
  53. y=FindParent(vec[i].b);
  54. if(x!=y){
  55. ans+=vec[i].w;
  56. parent[x]=y;
  57. }
  58. }
  59.  
  60. cout<<ans<<"\n";
  61.  
  62. }
Compilation error #stdin compilation error #stdout 0s 5296KB
stdin
5
0 0
2 2
3 10
5 2
7 0
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:52:29: error: cannot convert ‘point’ to ‘int’
         x=FindParent(vec[i].a);
prog.cpp:21:20: note:   initializing argument 1 of ‘int FindParent(int)’
 int FindParent(int i){
                ~~~~^
prog.cpp:53:29: error: cannot convert ‘point’ to ‘int’
         y=FindParent(vec[i].b);
prog.cpp:21:20: note:   initializing argument 1 of ‘int FindParent(int)’
 int FindParent(int i){
                ~~~~^
stdout
Standard output is empty