#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> p, r;
int n;
int get(int v)
{
return p[v] == 0 ? v : p[v] = get(p[v]);
}
void unio(int a, int b)
{
a = get(a);
b = get(b);
if(a != b)
{
if(r[a] < r[b]) swap(a, b);
p[b] = a;
if(r[a] == r[b]) r[a]++;
}
}
struct val
{
ll a, b, d;
};
bool insc(ll xa, ll xb, ll ya, ll yb)
{
if(ya == yb) return 0;
if(xb != xa)
{
ll x = xa * (yb - ya) + -ya * (xb - xa);
ll l = xa * (yb - ya), r = xb * (yb - ya);
if(l > r) swap(l, r);
return ((x > 0) ^ (ya > yb)) && x >= l && x <= r;
}
return xa > 0 && max(ya, yb) > 0 && min(ya, yb) < 0;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
p.resize(2 * n + 1);
r.resize(2 * n + 1);
vector<ll> x(n + 1), y(n + 1);
vector<val> e;
for(int i = 1; i <= n; i++)
{
cin >> x[i] >> y[i];
for(int j = 1; j < i; j++)
{
ll dx = x[i] - x[j], dy = y[i] - y[j];
e.push_back({j, i, dx * dx + dy * dy});
}
}
sort(e.begin(), e.end(), [](val a, val b)
{
return a.d < b.d;
});
for(auto [a, b, d] : e)
{
bool g = insc(x[a], x[b], y[a], y[b]);
//cout << a << " " << b << " " << d << " " << g << "\n";
if(g)
{
unio(a, b + n);
unio(a + n, b);
}
else
{
unio(a, b);
unio(a + n, b + n);
}
if(get(a) == get(a + n))
{
cout << d << "\n";
return 0;
}
}
cout << "-1\n";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2068 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Accepted | 3ms | 2276 KiB | ||||
4 | Wrong answer | 3ms | 2316 KiB | ||||
5 | Accepted | 3ms | 2448 KiB | ||||
6 | Accepted | 3ms | 2672 KiB | ||||
7 | Wrong answer | 3ms | 2768 KiB | ||||
8 | Accepted | 3ms | 2852 KiB | ||||
9 | Wrong answer | 3ms | 2984 KiB | ||||
10 | Wrong answer | 3ms | 3196 KiB | ||||
11 | Accepted | 3ms | 3268 KiB | ||||
12 | Accepted | 3ms | 3272 KiB | ||||
subtask3 | 0/20 | ||||||
13 | Accepted | 3ms | 2276 KiB | ||||
14 | Wrong answer | 3ms | 2316 KiB | ||||
15 | Accepted | 3ms | 2448 KiB | ||||
16 | Accepted | 3ms | 2672 KiB | ||||
17 | Wrong answer | 3ms | 2768 KiB | ||||
18 | Accepted | 3ms | 2852 KiB | ||||
19 | Wrong answer | 3ms | 2984 KiB | ||||
20 | Wrong answer | 3ms | 3196 KiB | ||||
21 | Accepted | 3ms | 3268 KiB | ||||
22 | Accepted | 3ms | 3272 KiB | ||||
23 | Accepted | 3ms | 3420 KiB | ||||
24 | Accepted | 3ms | 3612 KiB | ||||
25 | Wrong answer | 3ms | 3824 KiB | ||||
26 | Wrong answer | 3ms | 3912 KiB | ||||
27 | Accepted | 3ms | 4124 KiB | ||||
28 | Accepted | 3ms | 4220 KiB | ||||
29 | Accepted | 3ms | 4436 KiB | ||||
30 | Accepted | 3ms | 4432 KiB | ||||
31 | Accepted | 3ms | 4412 KiB | ||||
subtask4 | 0/20 | ||||||
32 | Accepted | 3ms | 2276 KiB | ||||
33 | Wrong answer | 3ms | 2316 KiB | ||||
34 | Accepted | 3ms | 2448 KiB | ||||
35 | Accepted | 3ms | 2672 KiB | ||||
36 | Wrong answer | 3ms | 2768 KiB | ||||
37 | Accepted | 3ms | 2852 KiB | ||||
38 | Wrong answer | 3ms | 2984 KiB | ||||
39 | Wrong answer | 3ms | 3196 KiB | ||||
40 | Accepted | 3ms | 3268 KiB | ||||
41 | Accepted | 3ms | 3272 KiB | ||||
42 | Accepted | 3ms | 3420 KiB | ||||
43 | Accepted | 3ms | 3612 KiB | ||||
44 | Wrong answer | 3ms | 3824 KiB | ||||
45 | Wrong answer | 3ms | 3912 KiB | ||||
46 | Accepted | 3ms | 4124 KiB | ||||
47 | Accepted | 3ms | 4220 KiB | ||||
48 | Accepted | 3ms | 4436 KiB | ||||
49 | Accepted | 3ms | 4432 KiB | ||||
50 | Accepted | 3ms | 4412 KiB | ||||
51 | Accepted | 3ms | 4792 KiB | ||||
52 | Accepted | 3ms | 4816 KiB | ||||
53 | Accepted | 3ms | 4812 KiB | ||||
54 | Accepted | 3ms | 5108 KiB | ||||
55 | Accepted | 3ms | 5112 KiB | ||||
56 | Accepted | 3ms | 5108 KiB | ||||
57 | Accepted | 3ms | 5044 KiB | ||||
58 | Accepted | 3ms | 5036 KiB | ||||
59 | Accepted | 3ms | 5008 KiB | ||||
60 | Accepted | 3ms | 5272 KiB | ||||
61 | Wrong answer | 3ms | 5220 KiB | ||||
62 | Wrong answer | 3ms | 5212 KiB | ||||
63 | Wrong answer | 3ms | 5244 KiB | ||||
64 | Wrong answer | 3ms | 5252 KiB | ||||
65 | Wrong answer | 3ms | 5216 KiB | ||||
66 | Accepted | 4ms | 5220 KiB | ||||
67 | Accepted | 4ms | 5496 KiB | ||||
68 | Accepted | 4ms | 5500 KiB | ||||
69 | Accepted | 3ms | 5532 KiB | ||||
70 | Accepted | 3ms | 5556 KiB | ||||
subtask5 | 0/40 | ||||||
71 | Accepted | 3ms | 2276 KiB | ||||
72 | Wrong answer | 3ms | 2316 KiB | ||||
73 | Accepted | 3ms | 2448 KiB | ||||
74 | Accepted | 3ms | 2672 KiB | ||||
75 | Wrong answer | 3ms | 2768 KiB | ||||
76 | Accepted | 3ms | 2852 KiB | ||||
77 | Wrong answer | 3ms | 2984 KiB | ||||
78 | Wrong answer | 3ms | 3196 KiB | ||||
79 | Accepted | 3ms | 3268 KiB | ||||
80 | Accepted | 3ms | 3272 KiB | ||||
81 | Accepted | 3ms | 3420 KiB | ||||
82 | Accepted | 3ms | 3612 KiB | ||||
83 | Wrong answer | 3ms | 3824 KiB | ||||
84 | Wrong answer | 3ms | 3912 KiB | ||||
85 | Accepted | 3ms | 4124 KiB | ||||
86 | Accepted | 3ms | 4220 KiB | ||||
87 | Accepted | 3ms | 4436 KiB | ||||
88 | Accepted | 3ms | 4432 KiB | ||||
89 | Accepted | 3ms | 4412 KiB | ||||
90 | Accepted | 3ms | 4792 KiB | ||||
91 | Accepted | 3ms | 4816 KiB | ||||
92 | Accepted | 3ms | 4812 KiB | ||||
93 | Accepted | 3ms | 5108 KiB | ||||
94 | Accepted | 3ms | 5112 KiB | ||||
95 | Accepted | 3ms | 5108 KiB | ||||
96 | Accepted | 3ms | 5044 KiB | ||||
97 | Accepted | 3ms | 5036 KiB | ||||
98 | Accepted | 3ms | 5008 KiB | ||||
99 | Accepted | 3ms | 5272 KiB | ||||
100 | Wrong answer | 3ms | 5220 KiB | ||||
101 | Wrong answer | 3ms | 5212 KiB | ||||
102 | Wrong answer | 3ms | 5244 KiB | ||||
103 | Wrong answer | 3ms | 5252 KiB | ||||
104 | Wrong answer | 3ms | 5216 KiB | ||||
105 | Accepted | 4ms | 5220 KiB | ||||
106 | Accepted | 4ms | 5496 KiB | ||||
107 | Accepted | 4ms | 5500 KiB | ||||
108 | Accepted | 3ms | 5532 KiB | ||||
109 | Accepted | 3ms | 5556 KiB | ||||
110 | Accepted | 86ms | 29684 KiB | ||||
111 | Wrong answer | 86ms | 29736 KiB | ||||
112 | Accepted | 82ms | 29784 KiB | ||||
113 | Accepted | 85ms | 29672 KiB | ||||
114 | Accepted | 82ms | 29664 KiB | ||||
115 | Wrong answer | 85ms | 29712 KiB | ||||
116 | Accepted | 90ms | 29716 KiB | ||||
117 | Accepted | 85ms | 29724 KiB | ||||
118 | Accepted | 89ms | 29716 KiB | ||||
119 | Accepted | 85ms | 29716 KiB | ||||
120 | Accepted | 89ms | 29712 KiB | ||||
121 | Accepted | 90ms | 29684 KiB | ||||
122 | Wrong answer | 90ms | 29740 KiB | ||||
123 | Wrong answer | 85ms | 29736 KiB | ||||
124 | Wrong answer | 89ms | 29712 KiB | ||||
125 | Wrong answer | 85ms | 29888 KiB | ||||
126 | Accepted | 93ms | 30016 KiB | ||||
127 | Accepted | 93ms | 30020 KiB | ||||
128 | Accepted | 96ms | 30024 KiB | ||||
129 | Accepted | 93ms | 29884 KiB | ||||
130 | Accepted | 97ms | 29928 KiB | ||||
131 | Accepted | 75ms | 29968 KiB | ||||
132 | Accepted | 97ms | 29976 KiB |