結果

問題 No.5007 Steiner Space Travel
ユーザー cho435
提出日時 2022-07-30 14:59:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,252 bytes
コンパイル時間 1,411 ms
実行使用メモリ 3,588 KB
スコア 4,521,707
最終ジャッジ日時 2022-07-30 14:59:49
合計ジャッジ時間 2,947 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
int fr(pair<int,int> &a,pair<int,int> &b){
return (a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second);
}
int fr(int a,int b,int x,int y){
return (a-x)*(a-x)+(b-y)*(b-y);
}
int main(){
int n,m;
cin>>n>>m;
vector<pair<int,int>> v(n);
rep(i,n){
cin>>v.at(i).first>>v.at(i).second;
}
vector<vector<int>> d(n,vector<int>(n,0));
rep(i,n){
for(int j=i+1;j<n;j++){
d.at(i).at(j)=fr(v.at(i),v.at(j));
d.at(j).at(i)=d.at(i).at(j);
}
}
vector<bool> stl(n,0);
vector<pair<int,int>> ccd(m,{0,0});
vector<pair<int,int>> ans;
ans.emplace_back(1,1);
stl.at(0)=1;
int nw=0;
rep(i,n-1){
int mn=1e9;
int mnct=-1;
rep(j,n){
if(stl.at(j)) continue;
if(mn>d.at(nw).at(j)){
mn=d.at(nw).at(j);
mnct=j;
}
}
if(mnct==-1){
cerr<<"#"<<endl;
break;
}
stl.at(mnct)=1;
ans.emplace_back(1,mnct+1);
nw=mnct;
}
ans.emplace_back(1,1);
for(auto ccdd:ccd){
cout<<ccdd.first<<" "<<ccdd.second<<endl;
}
cout<<ans.size()<<endl;
for(auto a:ans){
cout<<a.first<<" "<<a.second<<endl;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0