Problem p01279 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

bool dfs(int N, int M, vector<vector<bool>> &adj, vector<int> &a,
         vector<int> &b, int i, vector<bool> &vis) {
  vis[i] = true;
  for (int j = 0; j < M; j++) {
    if (!adj[i][j] || a[i] == j)
      continue;
    if (b[j] == -1) {
      b[j] = i;
      a[i] = j;
      return true;
    }
    int _i = b[j];
    if (!vis[_i] && dfs(N, M, adj, a, b, _i, vis)) {
      b[j] = i;
      a[i] = j;
      return true;
    }
  }
  return false;
}

int match(int N, int M, vector<vector<bool>> &adj) {
  vector<int> a(N, -1), b(M, -1);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] != -1)
      continue;
    vector<bool> vis(N);
    if (dfs(N, M, adj, a, b, i, vis))
      cnt++;
  }
  return cnt;
}

int main() {
  for (;;) {
    int N, M;
    cin >> N >> M;
    if (N == 0)
      break;
    vector<int> x(N), y(N), v(N);
    for (int i = 0; i < N; i++)
      cin >> x[i] >> y[i] >> v[i];
    vector<int> X(M), Y(M);
    for (int j = 0; j < M; j++)
      cin >> X[j] >> Y[j];
    double lb = 0, ub = 20000;
    for (int t = 0; t < 100; t++) {
      double mid = (lb + ub) / 2;
      vector<vector<bool>> adj(N, vector<bool>(M));
      for (int i = 0; i < N; i++)
        for (int j = 0; j < M; j++) {
          double dx = X[j] - x[i], dy = Y[j] - y[i];
          adj[i][j] = (sqrt(dx * dx + dy * dy) <= mid * v[i]);
        }
      if (match(N, M, adj) == M)
        ub = mid;
      else
        lb = mid;
    }
    printf("%.10f\\n", lb);
  }
}

Error: WA

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

bool dfs(int N, int M, vector<vector<bool>> &adj, vector<int> &a,
         vector<int> &b, int i, vector<bool> &vis) {
  vis[i] = true;
  for (int j = 0; j < M; j++) {
    if (!adj[i][j] || a[i] == j)
      continue;
    if (b[j] == -1) {
      b[j] = i;
      a[i] = j;
      return true;
    }
    for (int _i = 0; _i < N; _i++) {
      if (!adj[_i][j] || b[j] != _i)
        continue;
      if (dfs(N, M, adj, a, b, _i, vis)) {
        b[j] = i;
        a[i] = j;
        return true;
      }
    }
  }
  return false;
}

int match(int N, int M, vector<vector<bool>> &adj) {
  vector<int> a(N, -1), b(M, -1);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] != -1)
      continue;
    vector<bool> vis(N);
    if (dfs(N, M, adj, a, b, i, vis))
      cnt++;
  }
  return cnt;
}

int main() {
  for (;;) {
    int N, M;
    cin >> N >> M;
    if (N == 0)
      break;
    vector<int> x(N), y(N), v(N);
    for (int i = 0; i < N; i++)
      cin >> x[i] >> y[i] >> v[i];
    vector<int> X(M), Y(M);
    for (int j = 0; j < M; j++)
      cin >> X[j] >> Y[j];
    double lb = 0, ub = 20000;
    for (int t = 0; t < 20; t++) {
      double mid = (lb + ub) / 2;
      vector<vector<bool>> adj(N, vector<bool>(M));
      for (int i = 0; i < N; i++)
        for (int j = 0; j < M; j++) {
          double dx = X[j] - x[i], dy = Y[j] - y[i];
          adj[i][j] = (sqrt(dx * dx + dy * dy) <= mid * v[i]);
        }
      if (match(N, M, adj) == M)
        ub = mid;
      else
        lb = mid;
    }
    printf("%.10f\\n", lb);
  }
}