結果

問題 No.94 圏外です。(EASY)
ユーザー ninoinui
提出日時 2020-11-16 11:29:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,987 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 204,464 KB
最終ジャッジ日時 2025-01-16 01:05:26
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U> bool cmin(T &a, U b) { return a > b && (a = b, true); }
template <typename T, typename U> bool cmax(T &a, U b) { return a < b && (a = b, true); }
class UnionFind {
private:
int N;
vector<int> PS;
public:
UnionFind() : N(0) {}
UnionFind(int n) : N(n), PS(n, -1) {}
bool unite(int a, int b) {
int x = root(a), y = root(b);
if (x == y) return false;
if (-PS.at(x) < -PS.at(y)) swap(x, y);
PS.at(x) += PS.at(y);
PS.at(y) = x;
return true;
}
bool same(int a, int b) { return root(a) == root(b); }
int root(int a) {
if (PS.at(a) < 0) return a;
return PS.at(a) = root(PS.at(a));
}
int size(int a) { return -PS.at(root(a)); }
vector<vector<int>> groups() {
vector<int> B(N), S(N);
for (int i = 0; i < N; i++) {
B.at(i) = root(i);
S.at(B.at(i))++;
}
vector<vector<int>> ret(N);
for (int i = 0; i < N; i++) {
ret.at(i).reserve(S.at(i));
}
for (int i = 0; i < N; i++) {
ret.at(B.at(i)).push_back(i);
}
auto f = [&](const vector<int> &v) { return v.empty(); };
ret.erase(remove_if(ret.begin(), ret.end(), f), ret.end());
return ret;
}
};
signed main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
if (!N) return cout << 1 << "\n", 0;
vector<pair<int, int>> V(N);
for (int i = 0; i < N; i++) cin >> V.at(i).first >> V.at(i).second;
UnionFind UF(N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < i; j++) {
auto [a, b] = V.at(i);
auto [c, d] = V.at(j);
if (hypot(a - c, b - d) <= 10) UF.unite(i, j);
}
}
double mx = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < i; j++) {
auto [a, b] = V.at(i);
auto [c, d] = V.at(j);
if (UF.same(i, j)) cmax(mx, hypot(a - c, b - d));
}
}
if (mx == 0) return cout << 2 << "\n", 0;
cout << fixed << setprecision(6) << mx + 2 << "\n";
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0