109192024-04-18 21:54:18gortomiRajzcpp17Accepted 100/10098ms30028 KiB
#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";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2024 KiB
subtask220/20
3Accepted3ms2240 KiB
4Accepted3ms2464 KiB
5Accepted3ms2556 KiB
6Accepted3ms2776 KiB
7Accepted3ms2984 KiB
8Accepted3ms3108 KiB
9Accepted3ms3336 KiB
10Accepted3ms3532 KiB
11Accepted3ms3616 KiB
12Accepted3ms3768 KiB
subtask320/20
13Accepted3ms2240 KiB
14Accepted3ms2464 KiB
15Accepted3ms2556 KiB
16Accepted3ms2776 KiB
17Accepted3ms2984 KiB
18Accepted3ms3108 KiB
19Accepted3ms3336 KiB
20Accepted3ms3532 KiB
21Accepted3ms3616 KiB
22Accepted3ms3768 KiB
23Accepted3ms4008 KiB
24Accepted3ms4096 KiB
25Accepted3ms4168 KiB
26Accepted3ms4292 KiB
27Accepted3ms4376 KiB
28Accepted3ms4376 KiB
29Accepted3ms4356 KiB
30Accepted3ms4444 KiB
31Accepted3ms4412 KiB
subtask420/20
32Accepted3ms2240 KiB
33Accepted3ms2464 KiB
34Accepted3ms2556 KiB
35Accepted3ms2776 KiB
36Accepted3ms2984 KiB
37Accepted3ms3108 KiB
38Accepted3ms3336 KiB
39Accepted3ms3532 KiB
40Accepted3ms3616 KiB
41Accepted3ms3768 KiB
42Accepted3ms4008 KiB
43Accepted3ms4096 KiB
44Accepted3ms4168 KiB
45Accepted3ms4292 KiB
46Accepted3ms4376 KiB
47Accepted3ms4376 KiB
48Accepted3ms4356 KiB
49Accepted3ms4444 KiB
50Accepted3ms4412 KiB
51Accepted4ms5040 KiB
52Accepted3ms5324 KiB
53Accepted3ms5280 KiB
54Accepted3ms5236 KiB
55Accepted3ms5228 KiB
56Accepted3ms5520 KiB
57Accepted3ms5488 KiB
58Accepted3ms5492 KiB
59Accepted3ms5512 KiB
60Accepted3ms5548 KiB
61Accepted3ms5500 KiB
62Accepted3ms5472 KiB
63Accepted3ms5472 KiB
64Accepted3ms5508 KiB
65Accepted3ms5416 KiB
66Accepted3ms5420 KiB
67Accepted3ms5672 KiB
68Accepted3ms5628 KiB
69Accepted3ms5656 KiB
70Accepted3ms5660 KiB
subtask540/40
71Accepted3ms2240 KiB
72Accepted3ms2464 KiB
73Accepted3ms2556 KiB
74Accepted3ms2776 KiB
75Accepted3ms2984 KiB
76Accepted3ms3108 KiB
77Accepted3ms3336 KiB
78Accepted3ms3532 KiB
79Accepted3ms3616 KiB
80Accepted3ms3768 KiB
81Accepted3ms4008 KiB
82Accepted3ms4096 KiB
83Accepted3ms4168 KiB
84Accepted3ms4292 KiB
85Accepted3ms4376 KiB
86Accepted3ms4376 KiB
87Accepted3ms4356 KiB
88Accepted3ms4444 KiB
89Accepted3ms4412 KiB
90Accepted4ms5040 KiB
91Accepted3ms5324 KiB
92Accepted3ms5280 KiB
93Accepted3ms5236 KiB
94Accepted3ms5228 KiB
95Accepted3ms5520 KiB
96Accepted3ms5488 KiB
97Accepted3ms5492 KiB
98Accepted3ms5512 KiB
99Accepted3ms5548 KiB
100Accepted3ms5500 KiB
101Accepted3ms5472 KiB
102Accepted3ms5472 KiB
103Accepted3ms5508 KiB
104Accepted3ms5416 KiB
105Accepted3ms5420 KiB
106Accepted3ms5672 KiB
107Accepted3ms5628 KiB
108Accepted3ms5656 KiB
109Accepted3ms5660 KiB
110Accepted81ms29864 KiB
111Accepted85ms29864 KiB
112Accepted86ms29872 KiB
113Accepted86ms29864 KiB
114Accepted86ms29868 KiB
115Accepted81ms29864 KiB
116Accepted83ms29936 KiB
117Accepted83ms30028 KiB
118Accepted83ms29936 KiB
119Accepted86ms29868 KiB
120Accepted85ms29868 KiB
121Accepted85ms29868 KiB
122Accepted83ms29868 KiB
123Accepted85ms29756 KiB
124Accepted89ms29940 KiB
125Accepted85ms29864 KiB
126Accepted97ms29868 KiB
127Accepted92ms29916 KiB
128Accepted98ms29868 KiB
129Accepted90ms29916 KiB
130Accepted96ms29964 KiB
131Accepted75ms29976 KiB
132Accepted98ms29944 KiB