Problem p02805 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "algorithm"
#include "iostream"
#include "math.h"
#include "queue"
#include "stack"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "vector"
#define M 522
#define inf 100000000
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;
double X, Y;
struct Point {
  double x, y;
} p[M];
struct Triangle {
  Point v[3];
};
struct Circle {
  Point center;
  double r;
};
double pow(double x) { return x * x; }
double Len(Point a, Point b) { return sqrt(pow(a.x - b.x) + pow(a.y - b.y)); }
double TriangleArea(Triangle a) // 求三角形的面积
{
  double px1 = a.v[1].x - a.v[0].x;
  double py1 = a.v[1].y - a.v[0].y;
  double px2 = a.v[2].x - a.v[0].x;
  double py2 = a.v[2].y - a.v[0].y;
  return fabs(px1 * py2 - px2 * py1) / 2;
}
Circle CircleOfTriangle(Triangle t) // 就三角形外接圆
{
  Circle tmp;
  double a = Len(t.v[0], t.v[1]);
  double b = Len(t.v[0], t.v[2]);
  double c = Len(t.v[1], t.v[2]);
  tmp.r = a * b * c / 4 / TriangleArea(t);
  double a1 = t.v[1].x - t.v[0].x;
  double b1 = t.v[1].y - t.v[0].y;
  double c1 = (a1 * a1 + b1 * b1) / 2;
  double a2 = t.v[2].x - t.v[0].x;
  double b2 = t.v[2].y - t.v[0].y;
  double c2 = (a2 * a2 + b2 * b2) / 2;
  double d = a1 * b2 - a2 * b1;
  tmp.center.x = t.v[0].x + (c1 * b2 - c2 * b1) / d;
  tmp.center.y = t.v[0].y + (a1 * c2 - a2 * c1) / d;
  return tmp;
}
void Run(int n) {
  random_shuffle(p + 1, p + n + 1); // 随机排序取点
  int i, j, k;
  Circle tep;
  tep.center = p[1];
  tep.r = 0;
  for (i = 2; i <= n; i++) {
    if (Len(p[i], tep.center) > tep.r + eps) {
      tep.center = p[i];
      tep.r = 0;
      for (j = 1; j < i; j++) {
        if (Len(p[j], tep.center) > tep.r + eps) {
          tep.center.x = (p[i].x + p[j].x) / 2;
          tep.center.y = (p[i].y + p[j].y) / 2;
          tep.r = Len(p[i], p[j]) / 2;
          for (k = 1; k < j; k++) {
            if (Len(p[k], tep.center) > tep.r + eps) {
              Triangle t;
              t.v[0] = p[i];
              t.v[1] = p[j];
              t.v[2] = p[k];
              tep = CircleOfTriangle(t);
            }
          }
        }
      }
    }
  }
  printf("%.8lf\n", tep.r);
}
int main() {
  int n, i;
  while (scanf("%d", &n), n) {
    for (i = 1; i <= n; i++)
      scanf("%lf%lf", &p[i].x, &p[i].y);
    Run(n);
  }
}

Fixed submission:
#include "algorithm"
#include "iostream"
#include "math.h"
#include "queue"
#include "stack"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "vector"
#define M 522
#define inf 100000000
#define eps 1e-8
#define PI acos(-1.0)
using namespace std;
double X, Y;
struct Point {
  double x, y;
} p[M];
struct Triangle {
  Point v[3];
};
struct Circle {
  Point center;
  double r;
};
double pow(double x) { return x * x; }
double Len(Point a, Point b) { return sqrt(pow(a.x - b.x) + pow(a.y - b.y)); }
double TriangleArea(Triangle a) // 求三角形的面积
{
  double px1 = a.v[1].x - a.v[0].x;
  double py1 = a.v[1].y - a.v[0].y;
  double px2 = a.v[2].x - a.v[0].x;
  double py2 = a.v[2].y - a.v[0].y;
  return fabs(px1 * py2 - px2 * py1) / 2;
}
Circle CircleOfTriangle(Triangle t) // 就三角形外接圆
{
  Circle tmp;
  double a = Len(t.v[0], t.v[1]);
  double b = Len(t.v[0], t.v[2]);
  double c = Len(t.v[1], t.v[2]);
  tmp.r = a * b * c / 4 / TriangleArea(t);
  double a1 = t.v[1].x - t.v[0].x;
  double b1 = t.v[1].y - t.v[0].y;
  double c1 = (a1 * a1 + b1 * b1) / 2;
  double a2 = t.v[2].x - t.v[0].x;
  double b2 = t.v[2].y - t.v[0].y;
  double c2 = (a2 * a2 + b2 * b2) / 2;
  double d = a1 * b2 - a2 * b1;
  tmp.center.x = t.v[0].x + (c1 * b2 - c2 * b1) / d;
  tmp.center.y = t.v[0].y + (a1 * c2 - a2 * c1) / d;
  return tmp;
}
void Run(int n) {
  random_shuffle(p + 1, p + n + 1); // 随机排序取点
  int i, j, k;
  Circle tep;
  tep.center = p[1];
  tep.r = 0;
  for (i = 2; i <= n; i++) {
    if (Len(p[i], tep.center) > tep.r + eps) {
      tep.center = p[i];
      tep.r = 0;
      for (j = 1; j < i; j++) {
        if (Len(p[j], tep.center) > tep.r + eps) {
          tep.center.x = (p[i].x + p[j].x) / 2;
          tep.center.y = (p[i].y + p[j].y) / 2;
          tep.r = Len(p[i], p[j]) / 2;
          for (k = 1; k < j; k++) {
            if (Len(p[k], tep.center) > tep.r + eps) {
              Triangle t;
              t.v[0] = p[i];
              t.v[1] = p[j];
              t.v[2] = p[k];
              tep = CircleOfTriangle(t);
            }
          }
        }
      }
    }
  }
  printf("%.8lf\n", tep.r);
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%lf%lf", &p[i].x, &p[i].y);
  Run(n);
}