結果

問題 No.168 ものさし
コンテスト
ユーザー ciel
提出日時 2015-03-20 02:33:34
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,024 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 639 ms
コンパイル使用メモリ 75,520 KB
実行使用メモリ 27,392 KB
最終ジャッジ日時 2026-05-30 03:50:42
合計ジャッジ時間 2,227 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//kruskal tree
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define M 1000000
int parent[M],a[M],b[M];
pair<long long,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int same(int a,int b){
	int x=root(a),y=root(b);
	return x==y;
}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int N;
	scanf("%d",&N);
	{
		vector<pair<long long,long long> >V(N);
		for(int i=0;i<N;i++)scanf("%lld%lld",&V[i].first,&V[i].second);
		for(int i=0;i<N;i++){
			parent[i]=i;
			for(int j=0;j<N;j++){
				a[i*N+j]=i;
				b[i*N+j]=j;
				node[i*N+j].first=(V[i].first-V[j].first)*(V[i].first-V[j].first) + (V[i].second-V[j].second)*(V[i].second-V[j].second);
				node[i*N+j].second=i*N+j;
			}
		}
	}
	sort(node,node+N*N);
	long long ret=0;
	for(int q=0,i=0;/*q<N-1*/!same(0,N-1);i++)if(unite(a[node[i].second],b[node[i].second]))ret=max(ret,node[i].first),q++;
	printf("%.0Lf0\n",ceill(sqrtl(ret)/10));
}
0