結果
| 問題 |
No.94 圏外です。(EASY)
|
| コンテスト | |
| ユーザー |
uafr_cs
|
| 提出日時 | 2015-09-10 03:13:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 269 ms / 5,000 ms |
| コード長 | 1,745 bytes |
| コンパイル時間 | 2,545 ms |
| コンパイル使用メモリ | 78,676 KB |
| 実行使用メモリ | 44,568 KB |
| 最終ジャッジ日時 | 2024-06-26 07:43:05 |
| 合計ジャッジ時間 | 8,047 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static class UnionFind {
int[] par;
public UnionFind(int n) {
par = new int[n];
for(int i = 0; i < n; i++){
par[i] = i;
}
}
public int find(int x){
if(par[x] == x){
return x;
}else{
return par[x] = find(par[x]);
}
}
public boolean same(int x, int y){
return find(x) == find(y);
}
public boolean union(int x, int y){
final int x_root = find(x);
final int y_root = find(y);
if(x_root == y_root){ return false; }
par[y_root] = x_root;
return true;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int N = sc.nextInt();
int[] xs = new int[N];
int[] ys = new int[N];
for(int i = 0; i < N; i++){
xs[i] = sc.nextInt();
ys[i] = sc.nextInt();
}
UnionFind uf = new UnionFind(N);
for(int fst = 0; fst < N; fst++){
for(int snd = fst + 1; snd < N; snd++){
final int x_diff_2 = (xs[snd] - xs[fst]) * (xs[snd] - xs[fst]);
final int y_diff_2 = (ys[snd] - ys[fst]) * (ys[snd] - ys[fst]);
if(x_diff_2 + y_diff_2 <= 100){
uf.union(fst, snd);
}
}
}
//System.out.println(Arrays.toString(uf.par));
double max = N == 0 ? 1 : 2;
for(int fst = 0; fst < N; fst++){
for(int snd = fst + 1; snd < N; snd++){
if(uf.same(fst, snd)){
final int x_diff_2 = (xs[snd] - xs[fst]) * (xs[snd] - xs[fst]);
final int y_diff_2 = (ys[snd] - ys[fst]) * (ys[snd] - ys[fst]);
max = Math.max(max, Math.sqrt(x_diff_2 + y_diff_2) + 2);
}
}
}
System.out.printf("%.10f\n", max);
}
}
uafr_cs