55632023-07-27 11:22:11zsomborRajzcpp17Accepted 100/100149ms29872 KiB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll=long long;

struct point{
    ll x,y;
};

struct edge{
    int A,B,W;
    ll D;
    edge(int a,int b,int w,ll d){
        A=a;B=b;W=w;D=d;
    }
};

int n;
vector <point> v(1e3);
vector <edge> ed;
vector <int> p(2e3,0);
vector <int> sz(2e3,1);

int sgn(ll num){
    return (num>0)-(num<0);
}

int turn(point a, point b,point c){
    return sgn((c.y-a.y)*(b.x-a.x)-(b.y-a.y)*(c.x-a.x));
}

int intersection(point a,point b){
    point c,d;
    c.x=c.y=0;
    d.x=1;d.y=1e9+1;
    if (turn(a,b,c)*turn(a,b,d)>-1) return 0;
    if (turn(c,d,a)*turn(c,d,b)>-1) return 0;
    return 1;
}

ll dist(point a, point b){
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

bool srt(edge e,edge f){
    return (e.D<f.D?true:false);
}

int holvan(int a){
    return (a==p[a]?a:p[a]=holvan(p[a]));
}

void unio(int a,int b){
    a=holvan(a);
    b=holvan(b);
    if (a==b) return;
    if (sz[a]>sz[b]) swap(a,b);
    p[a]=b;
    sz[b]+=sz[a];
}

bool UNIO(edge e){
    if (e.W){
        unio(e.A,e.B+n);
        unio(e.A+n,e.B);
    }else{
        unio(e.A,e.B);
        unio(e.A+n,e.B+n);
    }
    return (holvan(e.A)==holvan(e.A+n)?true:false);
}

int main(){
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> v[i].x >> v[i].y;
        for (int j=0;j<i;j++){
            ed.push_back(edge(i,j,intersection(v[i],v[j]),dist(v[i],v[j])));
        }
    }
    sort(ed.begin(),ed.end(),srt);
    for (int i=0;i<2*n;i++) p[i]=i;
    for (edge e : ed){
        if (UNIO(e)){
            cout << e.D;
            return 0;
        }
    }
    cout << -1;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1908 KiB
2Accepted3ms2244 KiB
subtask220/20
3Accepted3ms2508 KiB
4Accepted3ms2720 KiB
5Accepted3ms2960 KiB
6Accepted3ms3164 KiB
7Accepted2ms3000 KiB
8Accepted3ms3208 KiB
9Accepted3ms3424 KiB
10Accepted3ms3512 KiB
11Accepted2ms3588 KiB
12Accepted2ms3508 KiB
subtask320/20
13Accepted3ms2508 KiB
14Accepted3ms2720 KiB
15Accepted3ms2960 KiB
16Accepted3ms3164 KiB
17Accepted2ms3000 KiB
18Accepted3ms3208 KiB
19Accepted3ms3424 KiB
20Accepted3ms3512 KiB
21Accepted2ms3588 KiB
22Accepted2ms3508 KiB
23Accepted3ms3652 KiB
24Accepted2ms3736 KiB
25Accepted3ms3976 KiB
26Accepted2ms3860 KiB
27Accepted3ms4008 KiB
28Accepted3ms3928 KiB
29Accepted3ms3988 KiB
30Accepted3ms4064 KiB
31Accepted2ms4128 KiB
subtask420/20
32Accepted3ms2508 KiB
33Accepted3ms2720 KiB
34Accepted3ms2960 KiB
35Accepted3ms3164 KiB
36Accepted2ms3000 KiB
37Accepted3ms3208 KiB
38Accepted3ms3424 KiB
39Accepted3ms3512 KiB
40Accepted2ms3588 KiB
41Accepted2ms3508 KiB
42Accepted3ms3652 KiB
43Accepted2ms3736 KiB
44Accepted3ms3976 KiB
45Accepted2ms3860 KiB
46Accepted3ms4008 KiB
47Accepted3ms3928 KiB
48Accepted3ms3988 KiB
49Accepted3ms4064 KiB
50Accepted2ms4128 KiB
51Accepted4ms4508 KiB
52Accepted3ms4524 KiB
53Accepted4ms4536 KiB
54Accepted4ms4532 KiB
55Accepted4ms4536 KiB
56Accepted4ms4516 KiB
57Accepted4ms4652 KiB
58Accepted4ms4792 KiB
59Accepted4ms4728 KiB
60Accepted4ms5000 KiB
61Accepted3ms4960 KiB
62Accepted4ms5064 KiB
63Accepted4ms5332 KiB
64Accepted4ms5296 KiB
65Accepted3ms5316 KiB
66Accepted4ms5316 KiB
67Accepted4ms5296 KiB
68Accepted4ms5288 KiB
69Accepted4ms5316 KiB
70Accepted4ms5340 KiB
subtask540/40
71Accepted3ms2508 KiB
72Accepted3ms2720 KiB
73Accepted3ms2960 KiB
74Accepted3ms3164 KiB
75Accepted2ms3000 KiB
76Accepted3ms3208 KiB
77Accepted3ms3424 KiB
78Accepted3ms3512 KiB
79Accepted2ms3588 KiB
80Accepted2ms3508 KiB
81Accepted3ms3652 KiB
82Accepted2ms3736 KiB
83Accepted3ms3976 KiB
84Accepted2ms3860 KiB
85Accepted3ms4008 KiB
86Accepted3ms3928 KiB
87Accepted3ms3988 KiB
88Accepted3ms4064 KiB
89Accepted2ms4128 KiB
90Accepted4ms4508 KiB
91Accepted3ms4524 KiB
92Accepted4ms4536 KiB
93Accepted4ms4532 KiB
94Accepted4ms4536 KiB
95Accepted4ms4516 KiB
96Accepted4ms4652 KiB
97Accepted4ms4792 KiB
98Accepted4ms4728 KiB
99Accepted4ms5000 KiB
100Accepted3ms4960 KiB
101Accepted4ms5064 KiB
102Accepted4ms5332 KiB
103Accepted4ms5296 KiB
104Accepted3ms5316 KiB
105Accepted4ms5316 KiB
106Accepted4ms5296 KiB
107Accepted4ms5288 KiB
108Accepted4ms5316 KiB
109Accepted4ms5340 KiB
110Accepted126ms29524 KiB
111Accepted126ms29600 KiB
112Accepted126ms29596 KiB
113Accepted127ms29468 KiB
114Accepted126ms29376 KiB
115Accepted126ms29376 KiB
116Accepted136ms29456 KiB
117Accepted136ms29372 KiB
118Accepted133ms29452 KiB
119Accepted133ms29524 KiB
120Accepted136ms29524 KiB
121Accepted134ms29440 KiB
122Accepted131ms29520 KiB
123Accepted136ms29520 KiB
124Accepted135ms29444 KiB
125Accepted133ms29524 KiB
126Accepted141ms29452 KiB
127Accepted143ms29376 KiB
128Accepted144ms29448 KiB
129Accepted141ms29444 KiB
130Accepted144ms29784 KiB
131Accepted115ms29656 KiB
132Accepted149ms29872 KiB