結果

問題 No.2179 Planet Traveler
ユーザー ぷらぷら
提出日時 2023-01-06 22:32:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,774 bytes
コンパイル時間 2,452 ms
コンパイル使用メモリ 214,716 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-05-07 22:12:28
合計ジャッジ時間 4,318 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 64 ms
15,740 KB
testcase_14 AC 62 ms
15,868 KB
testcase_15 AC 63 ms
15,740 KB
testcase_16 AC 63 ms
15,496 KB
testcase_17 AC 66 ms
15,740 KB
testcase_18 AC 64 ms
15,744 KB
testcase_19 AC 64 ms
15,740 KB
testcase_20 AC 9 ms
5,376 KB
testcase_21 AC 60 ms
15,736 KB
testcase_22 AC 38 ms
9,588 KB
testcase_23 AC 33 ms
9,716 KB
testcase_24 AC 48 ms
9,464 KB
testcase_25 AC 38 ms
9,464 KB
testcase_26 AC 58 ms
15,736 KB
testcase_27 AC 9 ms
5,376 KB
testcase_28 AC 27 ms
9,588 KB
testcase_29 AC 48 ms
9,716 KB
権限があれば一括ダウンロードができます

ソースコード

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 = ceil(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