結果

問題 No.2179 Planet Traveler
ユーザー ぷらぷら
提出日時 2023-01-06 22:31:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,775 bytes
コンパイル時間 2,568 ms
コンパイル使用メモリ 216,404 KB
実行使用メモリ 17,680 KB
最終ジャッジ日時 2024-05-07 22:11:54
合計ジャッジ時間 4,250 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 61 ms
15,740 KB
testcase_14 AC 59 ms
15,740 KB
testcase_15 AC 59 ms
15,740 KB
testcase_16 AC 58 ms
15,740 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> size;
    UnionFind(int n) {
        par.resize(n);
        size.resize(n,1);
        for(int i = 0; i < n; i++) {
            par[i] = i;
        }
    }
    int find(int x) {
        if(par[x] == x) {
            return x;
        }
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int consize(int x) {
        return size[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) {
            return false;
        }
        if(size[x] > size[y]) {
            swap(x,y);
        }
        par[x] = y;
        size[y] += size[x];
        return true;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<long long>X(N),Y(N),T(N);
    for(int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> T[i];
    }
    vector<array<long long,3>>tmp;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            int a = X[i]*X[i]+Y[i]*Y[i];
            int b = X[j]*X[j]+Y[j]*Y[j];
            if(T[i] == T[j]) {
                long long c = (X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]);
                tmp.push_back({c,i,j});
            }
            else {
                if(a < b) swap(a,b);
                long long c = floor(a+b-2.0*sqrt(1ll*a*b));
                tmp.push_back({c,i,j});
            }
        }
    }
    sort(tmp.begin(),tmp.end());
    UnionFind uf(N);
    for(int i = 0; i < tmp.size(); i++) {
        uf.unite(tmp[i][1],tmp[i][2]);
        if(uf.same(0,N-1)) {
            cout << tmp[i][0] << endl;
            return 0;
        }
    }
}
0