結果
| 問題 |
No.94 圏外です。(EASY)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-25 02:02:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 431 ms / 5,000 ms |
| コード長 | 1,210 bytes |
| コンパイル時間 | 2,312 ms |
| コンパイル使用メモリ | 77,204 KB |
| 実行使用メモリ | 51,120 KB |
| 最終ジャッジ日時 | 2024-06-26 07:54:10 |
| 合計ジャッジ時間 | 10,283 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
package yukicoder094;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
double[] x=new double[n];
double[] y=new double[n];
UnionFind uni=new UnionFind(n);
for(int i=0;i<n;i++){
x[i]=sc.nextDouble();
y[i]=sc.nextDouble();
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
if((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<=100){
uni.setUnion(i, j);
}
}
}
double max=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
if(uni.root(i)==uni.root(j)){
max=Math.max(max,(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
}
}
if(n==0){
System.out.println(1);
return;
}else{
System.out.println(Math.sqrt(max)+2);
}
}
static class UnionFind{
int[] f;
UnionFind(int size){
f=new int[size];
Arrays.fill(f, -1);
}
boolean setUnion(int x,int y){
x=root(x);
y=root(y);
if(x!=y){
if(f[x]>f[y]){
int d=x;
x=y;
y=d;
}
f[x]+=f[y];
f[y]=x;
}
return x!=y;
}
int root(int x){
return f[x]<0?x:root(f[x]);
}
}
}