Problem p02861 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x, y) make_pair(x, y)
#define all(x) x.begin(), x.end()

typedef long long int ll;

ll general, total;
// ll chk[55];
// ll num[55];
// ll num2[55];
// ll num[ten5];
// ll num2[ten5];
// char cmap[10][10];
// priority_queue<ll> pqll;   //decrease
priority_queue<double> pqd;
// stack<int> stk;
vector<pair<ll, ll>> vpll;
vector<pair<double, double>> vpdd;
// vector<ll> vll;
// vector<double> vd;
// deque<ll> deq[55];
// list<int> li;
// set<int> sint;
// set<ll> sll;
// map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/

int main() {
  double ans = 0.0, half, d, d1, d2;
  // float f,g,h;
  long long int sum, sum2, n1, n2, n3;
  long long int m, n, o, i, j, k = 1;
  long long int a, a1, a2, a3, a4, a5, a6;
  sum = sum2 = n1 = n2 = n3 = 0;
  a = a1 = a2 = a3 = a4 = a5 = a6 = 0;
  // string s,s1;
  // char now,pre,c;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a1 >> a2;
    vpll.pb(mkpr(a1, a2));
    // vpdd.pb(mkpr(d1,d2));
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      /*d1=abs(vpdd[i].first-vpdd[j].first);
      d2=abs(vpdd[i].second-vpdd[j].second);*/
      d1 = (double)abs(vpll[i].first - vpll[j].first);
      d2 = (double)abs(vpll[i].second - vpll[j].second);
      ans += sqrt(d1 * d1 + d2 * d2);
    }
  }
  ans = ans * 2 / n;
  printf("%.6llf", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x, y) make_pair(x, y)
#define all(x) x.begin(), x.end()

typedef long long int ll;

ll general, total;
// ll chk[55];
// ll num[55];
// ll num2[55];
// ll num[ten5];
// ll num2[ten5];
// char cmap[10][10];
// priority_queue<ll> pqll;   //decrease
priority_queue<double> pqd;
// stack<int> stk;
vector<pair<ll, ll>> vpll;
vector<pair<double, double>> vpdd;
// vector<ll> vll;
// vector<double> vd;
// deque<ll> deq[55];
// list<int> li;
// set<int> sint;
// set<ll> sll;
// map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/

int main() {
  double ans = 0.0, half, d, d1, d2;
  // float f,g,h;
  long long int sum, sum2, n1, n2, n3;
  long long int m, n, o, i, j, k = 1;
  long long int a, a1, a2, a3, a4, a5, a6;
  sum = sum2 = n1 = n2 = n3 = 0;
  a = a1 = a2 = a3 = a4 = a5 = a6 = 0;
  // string s,s1;
  // char now,pre,c;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a1 >> a2;
    vpll.pb(mkpr(a1, a2));
    // vpdd.pb(mkpr(d1,d2));
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      /*d1=abs(vpdd[i].first-vpdd[j].first);
      d2=abs(vpdd[i].second-vpdd[j].second);*/
      d1 = (double)abs(vpll[i].first - vpll[j].first);
      d2 = (double)abs(vpll[i].second - vpll[j].second);
      ans += sqrt(d1 * d1 + d2 * d2);
    }
  }
  ans = ans * 2 / n;
  printf("%.7lf", ans);
  return 0;
}