結果
問題 |
No.94 圏外です。(EASY)
|
ユーザー |
|
提出日時 | 2015-06-30 13:38:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 16 ms / 5,000 ms |
コード長 | 1,416 bytes |
コンパイル時間 | 815 ms |
コンパイル使用メモリ | 75,188 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-06-26 07:36:16 |
合計ジャッジ時間 | 1,792 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <string> #include <cmath> using namespace std; class UnionFind { public: vector<int> parent; int trees; UnionFind(int n) { trees = n; parent.assign(n, 0); for (int i = 0; i < n; i++) { parent[i] = i; } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x != y) { parent[x] = y; trees--; } } int count() { return trees; } }; int main() { int n; cin >> n; if (n == 0) { cout << 1 << endl; return 0; } vector<int> x(n, 0), y(n, 0); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } vector< vector<double> > len(n, vector<double>(n, 0)); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { len[i][j] = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)); len[j][i] = len[i][j]; } } UnionFind uf(n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (len[i][j] <= 10.0) { uf.unite(i, j); } } } double max_len = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (uf.same(i, j)) { max_len= max(max_len, len[i][j]); } } } max_len += 2; printf("%.9lf\n", max_len); return 0; }