結果
| 問題 |
No.2179 Planet Traveler
|
| コンテスト | |
| ユーザー |
ぷら
|
| 提出日時 | 2023-01-06 22:31:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,775 bytes |
| コンパイル時間 | 2,522 ms |
| コンパイル使用メモリ | 208,564 KB |
| 最終ジャッジ日時 | 2025-02-10 00:10:14 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 6 WA * 20 |
ソースコード
#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;
}
}
}
ぷら