#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 cross(ll x1, ll y1, ll x2, ll y2)
{
return x1 * y2 - x2 * y1 < 0;
}
bool insc(ll xa, ll xb, ll ya, ll yb)
{
ll xd = 2e9 + 5, yd = 1, xc = 0, yc = 0;
return (cross(xb - xa, yb - ya, xc - xa, yc - ya) != cross(xb - xa, yb - ya, xd - xa, yd - ya)) &&
(cross(xd - xc, yd - yc, xa - xc, ya - yc) != cross(xd - xc, yd - yc, xb - xc, yb - yc));
}
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 | 1832 KiB | ||||
2 | Accepted | 3ms | 2024 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2240 KiB | ||||
4 | Accepted | 3ms | 2464 KiB | ||||
5 | Accepted | 3ms | 2556 KiB | ||||
6 | Accepted | 3ms | 2776 KiB | ||||
7 | Accepted | 3ms | 2984 KiB | ||||
8 | Accepted | 3ms | 3108 KiB | ||||
9 | Accepted | 3ms | 3336 KiB | ||||
10 | Accepted | 3ms | 3532 KiB | ||||
11 | Accepted | 3ms | 3616 KiB | ||||
12 | Accepted | 3ms | 3768 KiB | ||||
subtask3 | 20/20 | ||||||
13 | Accepted | 3ms | 2240 KiB | ||||
14 | Accepted | 3ms | 2464 KiB | ||||
15 | Accepted | 3ms | 2556 KiB | ||||
16 | Accepted | 3ms | 2776 KiB | ||||
17 | Accepted | 3ms | 2984 KiB | ||||
18 | Accepted | 3ms | 3108 KiB | ||||
19 | Accepted | 3ms | 3336 KiB | ||||
20 | Accepted | 3ms | 3532 KiB | ||||
21 | Accepted | 3ms | 3616 KiB | ||||
22 | Accepted | 3ms | 3768 KiB | ||||
23 | Accepted | 3ms | 4008 KiB | ||||
24 | Accepted | 3ms | 4096 KiB | ||||
25 | Accepted | 3ms | 4168 KiB | ||||
26 | Accepted | 3ms | 4292 KiB | ||||
27 | Accepted | 3ms | 4376 KiB | ||||
28 | Accepted | 3ms | 4376 KiB | ||||
29 | Accepted | 3ms | 4356 KiB | ||||
30 | Accepted | 3ms | 4444 KiB | ||||
31 | Accepted | 3ms | 4412 KiB | ||||
subtask4 | 20/20 | ||||||
32 | Accepted | 3ms | 2240 KiB | ||||
33 | Accepted | 3ms | 2464 KiB | ||||
34 | Accepted | 3ms | 2556 KiB | ||||
35 | Accepted | 3ms | 2776 KiB | ||||
36 | Accepted | 3ms | 2984 KiB | ||||
37 | Accepted | 3ms | 3108 KiB | ||||
38 | Accepted | 3ms | 3336 KiB | ||||
39 | Accepted | 3ms | 3532 KiB | ||||
40 | Accepted | 3ms | 3616 KiB | ||||
41 | Accepted | 3ms | 3768 KiB | ||||
42 | Accepted | 3ms | 4008 KiB | ||||
43 | Accepted | 3ms | 4096 KiB | ||||
44 | Accepted | 3ms | 4168 KiB | ||||
45 | Accepted | 3ms | 4292 KiB | ||||
46 | Accepted | 3ms | 4376 KiB | ||||
47 | Accepted | 3ms | 4376 KiB | ||||
48 | Accepted | 3ms | 4356 KiB | ||||
49 | Accepted | 3ms | 4444 KiB | ||||
50 | Accepted | 3ms | 4412 KiB | ||||
51 | Accepted | 4ms | 5040 KiB | ||||
52 | Accepted | 3ms | 5324 KiB | ||||
53 | Accepted | 3ms | 5280 KiB | ||||
54 | Accepted | 3ms | 5236 KiB | ||||
55 | Accepted | 3ms | 5228 KiB | ||||
56 | Accepted | 3ms | 5520 KiB | ||||
57 | Accepted | 3ms | 5488 KiB | ||||
58 | Accepted | 3ms | 5492 KiB | ||||
59 | Accepted | 3ms | 5512 KiB | ||||
60 | Accepted | 3ms | 5548 KiB | ||||
61 | Accepted | 3ms | 5500 KiB | ||||
62 | Accepted | 3ms | 5472 KiB | ||||
63 | Accepted | 3ms | 5472 KiB | ||||
64 | Accepted | 3ms | 5508 KiB | ||||
65 | Accepted | 3ms | 5416 KiB | ||||
66 | Accepted | 3ms | 5420 KiB | ||||
67 | Accepted | 3ms | 5672 KiB | ||||
68 | Accepted | 3ms | 5628 KiB | ||||
69 | Accepted | 3ms | 5656 KiB | ||||
70 | Accepted | 3ms | 5660 KiB | ||||
subtask5 | 40/40 | ||||||
71 | Accepted | 3ms | 2240 KiB | ||||
72 | Accepted | 3ms | 2464 KiB | ||||
73 | Accepted | 3ms | 2556 KiB | ||||
74 | Accepted | 3ms | 2776 KiB | ||||
75 | Accepted | 3ms | 2984 KiB | ||||
76 | Accepted | 3ms | 3108 KiB | ||||
77 | Accepted | 3ms | 3336 KiB | ||||
78 | Accepted | 3ms | 3532 KiB | ||||
79 | Accepted | 3ms | 3616 KiB | ||||
80 | Accepted | 3ms | 3768 KiB | ||||
81 | Accepted | 3ms | 4008 KiB | ||||
82 | Accepted | 3ms | 4096 KiB | ||||
83 | Accepted | 3ms | 4168 KiB | ||||
84 | Accepted | 3ms | 4292 KiB | ||||
85 | Accepted | 3ms | 4376 KiB | ||||
86 | Accepted | 3ms | 4376 KiB | ||||
87 | Accepted | 3ms | 4356 KiB | ||||
88 | Accepted | 3ms | 4444 KiB | ||||
89 | Accepted | 3ms | 4412 KiB | ||||
90 | Accepted | 4ms | 5040 KiB | ||||
91 | Accepted | 3ms | 5324 KiB | ||||
92 | Accepted | 3ms | 5280 KiB | ||||
93 | Accepted | 3ms | 5236 KiB | ||||
94 | Accepted | 3ms | 5228 KiB | ||||
95 | Accepted | 3ms | 5520 KiB | ||||
96 | Accepted | 3ms | 5488 KiB | ||||
97 | Accepted | 3ms | 5492 KiB | ||||
98 | Accepted | 3ms | 5512 KiB | ||||
99 | Accepted | 3ms | 5548 KiB | ||||
100 | Accepted | 3ms | 5500 KiB | ||||
101 | Accepted | 3ms | 5472 KiB | ||||
102 | Accepted | 3ms | 5472 KiB | ||||
103 | Accepted | 3ms | 5508 KiB | ||||
104 | Accepted | 3ms | 5416 KiB | ||||
105 | Accepted | 3ms | 5420 KiB | ||||
106 | Accepted | 3ms | 5672 KiB | ||||
107 | Accepted | 3ms | 5628 KiB | ||||
108 | Accepted | 3ms | 5656 KiB | ||||
109 | Accepted | 3ms | 5660 KiB | ||||
110 | Accepted | 81ms | 29864 KiB | ||||
111 | Accepted | 85ms | 29864 KiB | ||||
112 | Accepted | 86ms | 29872 KiB | ||||
113 | Accepted | 86ms | 29864 KiB | ||||
114 | Accepted | 86ms | 29868 KiB | ||||
115 | Accepted | 81ms | 29864 KiB | ||||
116 | Accepted | 83ms | 29936 KiB | ||||
117 | Accepted | 83ms | 30028 KiB | ||||
118 | Accepted | 83ms | 29936 KiB | ||||
119 | Accepted | 86ms | 29868 KiB | ||||
120 | Accepted | 85ms | 29868 KiB | ||||
121 | Accepted | 85ms | 29868 KiB | ||||
122 | Accepted | 83ms | 29868 KiB | ||||
123 | Accepted | 85ms | 29756 KiB | ||||
124 | Accepted | 89ms | 29940 KiB | ||||
125 | Accepted | 85ms | 29864 KiB | ||||
126 | Accepted | 97ms | 29868 KiB | ||||
127 | Accepted | 92ms | 29916 KiB | ||||
128 | Accepted | 98ms | 29868 KiB | ||||
129 | Accepted | 90ms | 29916 KiB | ||||
130 | Accepted | 96ms | 29964 KiB | ||||
131 | Accepted | 75ms | 29976 KiB | ||||
132 | Accepted | 98ms | 29944 KiB |