#include <bits/stdc++.h>
#define inf 100000000.00
using namespace std;
struct Pos {
double x, y;
} place[155];
double arrmax[155];
struct edge {
int y;
double z;
};
double dist(Pos x, Pos y) {
return 1.0 * sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));
}
double dis[155][155];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> place[i].x >> place[i].y;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
char c;
cin >> c;
if (c == '1')
dis[i][j] = dist(place[i], place[j]);
else
dis[i][j] = inf;
}
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j)
continue;
if (dis[i][k] == inf || dis[k][j] == inf)
continue;
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j || dis[i][j] == inf)
continue;
arrmax[i] = max(arrmax[i], dis[i][j]);
}
}
double minn = 9999999.0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j || dis[i][j] != inf)
continue;
minn = min(minn, arrmax[i] + arrmax[j] + dist(place[i], place[j]));
}
}
printf("%.6lf", minn);
return 0;
}