#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> p, r;
int n;
int get(int v)
{
if(v > 2 * n || v <= 0) cout << "-1" << endl;
return p[v] == 0 ? v : p[v] = get(p[v]);
}
void unio(int a, int b)
{
a = get(a);
b = get(b);
if(a > 2 * n || b > 2 * n || a == 0 || b == 0) cout << "-1" << endl;
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)
{
long double b = (yb - ya) / (xb - xa);
if(b == 0) return 0;
long double x = xa + (-ya / b);
return x > 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]);
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 | 1828 KiB | ||||
2 | Wrong answer | 3ms | 2064 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Accepted | 3ms | 2516 KiB | ||||
4 | Wrong answer | 3ms | 2520 KiB | ||||
5 | Runtime error | 3ms | 2848 KiB | ||||
6 | Wrong answer | 3ms | 2788 KiB | ||||
7 | Wrong answer | 3ms | 2848 KiB | ||||
8 | Wrong answer | 3ms | 3036 KiB | ||||
9 | Accepted | 3ms | 3244 KiB | ||||
10 | Wrong answer | 3ms | 3592 KiB | ||||
11 | Accepted | 3ms | 3452 KiB | ||||
12 | Accepted | 3ms | 3572 KiB | ||||
subtask3 | 0/20 | ||||||
13 | Accepted | 3ms | 2516 KiB | ||||
14 | Wrong answer | 3ms | 2520 KiB | ||||
15 | Runtime error | 3ms | 2848 KiB | ||||
16 | Wrong answer | 3ms | 2788 KiB | ||||
17 | Wrong answer | 3ms | 2848 KiB | ||||
18 | Wrong answer | 3ms | 3036 KiB | ||||
19 | Accepted | 3ms | 3244 KiB | ||||
20 | Wrong answer | 3ms | 3592 KiB | ||||
21 | Accepted | 3ms | 3452 KiB | ||||
22 | Accepted | 3ms | 3572 KiB | ||||
23 | Runtime error | 3ms | 3684 KiB | ||||
24 | Runtime error | 3ms | 3928 KiB | ||||
25 | Wrong answer | 3ms | 3940 KiB | ||||
26 | Wrong answer | 3ms | 4004 KiB | ||||
27 | Wrong answer | 3ms | 4072 KiB | ||||
28 | Wrong answer | 3ms | 4136 KiB | ||||
29 | Accepted | 3ms | 4208 KiB | ||||
30 | Wrong answer | 3ms | 4212 KiB | ||||
31 | Runtime error | 3ms | 4168 KiB | ||||
subtask4 | 0/20 | ||||||
32 | Accepted | 3ms | 2516 KiB | ||||
33 | Wrong answer | 3ms | 2520 KiB | ||||
34 | Runtime error | 3ms | 2848 KiB | ||||
35 | Wrong answer | 3ms | 2788 KiB | ||||
36 | Wrong answer | 3ms | 2848 KiB | ||||
37 | Wrong answer | 3ms | 3036 KiB | ||||
38 | Accepted | 3ms | 3244 KiB | ||||
39 | Wrong answer | 3ms | 3592 KiB | ||||
40 | Accepted | 3ms | 3452 KiB | ||||
41 | Accepted | 3ms | 3572 KiB | ||||
42 | Runtime error | 3ms | 3684 KiB | ||||
43 | Runtime error | 3ms | 3928 KiB | ||||
44 | Wrong answer | 3ms | 3940 KiB | ||||
45 | Wrong answer | 3ms | 4004 KiB | ||||
46 | Wrong answer | 3ms | 4072 KiB | ||||
47 | Wrong answer | 3ms | 4136 KiB | ||||
48 | Accepted | 3ms | 4208 KiB | ||||
49 | Wrong answer | 3ms | 4212 KiB | ||||
50 | Runtime error | 3ms | 4168 KiB | ||||
51 | Runtime error | 3ms | 4740 KiB | ||||
52 | Runtime error | 4ms | 5060 KiB | ||||
53 | Runtime error | 4ms | 4868 KiB | ||||
54 | Runtime error | 4ms | 5068 KiB | ||||
55 | Runtime error | 3ms | 5108 KiB | ||||
56 | Wrong answer | 4ms | 4892 KiB | ||||
57 | Wrong answer | 3ms | 4812 KiB | ||||
58 | Wrong answer | 3ms | 4836 KiB | ||||
59 | Wrong answer | 3ms | 4812 KiB | ||||
60 | Wrong answer | 3ms | 4816 KiB | ||||
61 | Runtime error | 4ms | 5416 KiB | ||||
62 | Wrong answer | 3ms | 5528 KiB | ||||
63 | Runtime error | 3ms | 5564 KiB | ||||
64 | Wrong answer | 3ms | 5492 KiB | ||||
65 | Wrong answer | 3ms | 5524 KiB | ||||
66 | Runtime error | 3ms | 5552 KiB | ||||
67 | Wrong answer | 3ms | 5376 KiB | ||||
68 | Wrong answer | 3ms | 5660 KiB | ||||
69 | Accepted | 3ms | 5652 KiB | ||||
70 | Wrong answer | 3ms | 5592 KiB | ||||
subtask5 | 0/40 | ||||||
71 | Accepted | 3ms | 2516 KiB | ||||
72 | Wrong answer | 3ms | 2520 KiB | ||||
73 | Runtime error | 3ms | 2848 KiB | ||||
74 | Wrong answer | 3ms | 2788 KiB | ||||
75 | Wrong answer | 3ms | 2848 KiB | ||||
76 | Wrong answer | 3ms | 3036 KiB | ||||
77 | Accepted | 3ms | 3244 KiB | ||||
78 | Wrong answer | 3ms | 3592 KiB | ||||
79 | Accepted | 3ms | 3452 KiB | ||||
80 | Accepted | 3ms | 3572 KiB | ||||
81 | Runtime error | 3ms | 3684 KiB | ||||
82 | Runtime error | 3ms | 3928 KiB | ||||
83 | Wrong answer | 3ms | 3940 KiB | ||||
84 | Wrong answer | 3ms | 4004 KiB | ||||
85 | Wrong answer | 3ms | 4072 KiB | ||||
86 | Wrong answer | 3ms | 4136 KiB | ||||
87 | Accepted | 3ms | 4208 KiB | ||||
88 | Wrong answer | 3ms | 4212 KiB | ||||
89 | Runtime error | 3ms | 4168 KiB | ||||
90 | Runtime error | 3ms | 4740 KiB | ||||
91 | Runtime error | 4ms | 5060 KiB | ||||
92 | Runtime error | 4ms | 4868 KiB | ||||
93 | Runtime error | 4ms | 5068 KiB | ||||
94 | Runtime error | 3ms | 5108 KiB | ||||
95 | Wrong answer | 4ms | 4892 KiB | ||||
96 | Wrong answer | 3ms | 4812 KiB | ||||
97 | Wrong answer | 3ms | 4836 KiB | ||||
98 | Wrong answer | 3ms | 4812 KiB | ||||
99 | Wrong answer | 3ms | 4816 KiB | ||||
100 | Runtime error | 4ms | 5416 KiB | ||||
101 | Wrong answer | 3ms | 5528 KiB | ||||
102 | Runtime error | 3ms | 5564 KiB | ||||
103 | Wrong answer | 3ms | 5492 KiB | ||||
104 | Wrong answer | 3ms | 5524 KiB | ||||
105 | Runtime error | 3ms | 5552 KiB | ||||
106 | Wrong answer | 3ms | 5376 KiB | ||||
107 | Wrong answer | 3ms | 5660 KiB | ||||
108 | Accepted | 3ms | 5652 KiB | ||||
109 | Wrong answer | 3ms | 5592 KiB | ||||
110 | Runtime error | 79ms | 29828 KiB | ||||
111 | Runtime error | 79ms | 29920 KiB | ||||
112 | Runtime error | 79ms | 29776 KiB | ||||
113 | Runtime error | 79ms | 29780 KiB | ||||
114 | Runtime error | 79ms | 29704 KiB | ||||
115 | Runtime error | 79ms | 29808 KiB | ||||
116 | Wrong answer | 82ms | 29784 KiB | ||||
117 | Wrong answer | 82ms | 29840 KiB | ||||
118 | Wrong answer | 82ms | 29820 KiB | ||||
119 | Wrong answer | 82ms | 29688 KiB | ||||
120 | Wrong answer | 82ms | 29680 KiB | ||||
121 | Wrong answer | 82ms | 29684 KiB | ||||
122 | Runtime error | 82ms | 29684 KiB | ||||
123 | Wrong answer | 82ms | 29760 KiB | ||||
124 | Runtime error | 82ms | 29704 KiB | ||||
125 | Wrong answer | 82ms | 29812 KiB | ||||
126 | Runtime error | 81ms | 29684 KiB | ||||
127 | Runtime error | 82ms | 29688 KiB | ||||
128 | Runtime error | 82ms | 29680 KiB | ||||
129 | Runtime error | 81ms | 29772 KiB | ||||
130 | Wrong answer | 81ms | 29868 KiB | ||||
131 | Accepted | 101ms | 29864 KiB | ||||
132 | Wrong answer | 82ms | 29680 KiB |