結果

問題 No.2353 Guardian Dogs in Spring
ユーザー Taiki0715Taiki0715
提出日時 2023-06-16 21:48:16
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 4,752 bytes
コンパイル時間 7,851 ms
コンパイル使用メモリ 130,800 KB
実行使用メモリ 532,360 KB
最終ジャッジ日時 2023-09-06 19:17:39
合計ジャッジ時間 9,642 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cassert>
#include <bitset>
#include <map>
#include <algorithm>
#include <iterator>
#include <string>
#include <utility>
#include <numeric>
#include <regex>
#include <complex>
#include <random>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> ostream &operator<<(ostream &os,const vector<T> &a){cout<<'{';for(int i=0;i<a.size();i++){cout<<a[i];if(i+1!=a.size())cout<<',';};cout<<'}';return os;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcount(x)
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T1,typename ...T2>
void debug(const T1& x,const T2& ...y){
  #ifdef LOCAL
  cout<<x;
  ((cout<<' '<<y),...);
  cout<<'\n';
  #endif
}
void SOLVE();
int main(){
  #ifdef LOCAL
  clock_t start=clock();
  #endif
  int testcase=1;
  //cin>>testcase;
  for(int i=0;i<testcase;i++){
    SOLVE();
  }
  #ifdef LOCAL
  cout<<"time:";
  cout<<(clock()-start)/1000;
  cout<<"ms\n";
  #endif
}
using R=double;
using Point=complex<R>;
constexpr R eps=1e-12;
constexpr R pi=3.141592653589793238;
inline bool equal(const R &a,const R &b){
  return fabs(a-b)<eps;
}
Point unit_vector(const Point &a){return a/abs(a);}
R dot(const Point &a,const Point &b){//内積
  return a.real()*b.real()+a.imag()*b.imag();
}
R cross(const Point &a,const Point &b){//外積
  return a.real()*b.imag()-a.imag()*b.real();
}
Point rotate(const Point &a,const R t){
  return Point(cos(t)*a.real()-sin(t)*a.imag(),sin(t)*a.real()+cos(t)*a.imag());
}
struct Line{
  Point a,b;
  Line():a(Point(0,0)),b(Point(0,0)){};
  Line(Point a,Point b):a(a),b(b){}
  Line(R A,R B,R C){
    assert(!(equal(A,0)&&equal(B,0)));
    if(equal(A,0)){
      a=Point(0,C/B),b=Point(1,C/B);
    }
    else if(equal(B,0)){
      a=Point(C/A,0),b=Point(C/A,1);
    }
    else{
      a=Point(C/A,0),b=Point(0,C/B);
    }
  }
};
Point projection(const Line &line,const Point &p){
  R t=dot(p-line.a,line.a-line.b)/norm(line.a-line.b);
  return line.a+(line.a-line.b)*t;
}
Point reflection(const Line &line,const Point &p){
  return p+(projection(line,p)-p)*(R)2;
}
bool ON(const Point &a,const Point &b,const Point &p){
  if(a==p)return true;
  if(b==p)return true;
  if(!equal(cross(a-p,b-p),0))return false;
  return dot(a-p,b-p)<0;
}
Point crosspoint(const Line &a,const Line &b){
  R c=cross(a.b-a.a,b.b-b.a);
  R d=cross(a.b-a.a,a.b-b.a);
  if(equal(abs(c),0)&&equal(abs(d),0))return b.a;
  return b.a+(b.b-b.a)*d/c;
}
Line suityokunitoubunsenn(const Point &a,const Point &b){
  Point c=(a+b)*(R)0.5;
  Point d=rotate(a-c,pi/2)+c;
  Line ret(c,d);
  return ret;
}
struct Circle{
  Point p;
  R r;
  Circle():p(Point(0,0)),r(0){};
  Circle(Point p,R r):p(p),r(r){}
  Circle(Point a,Point b,Point c){
    assert(!equal(cross(b-a,c-a),0));
    Line x=suityokunitoubunsenn(a,b),y=suityokunitoubunsenn(a,c);
    p=crosspoint(x,y);
    r=abs(a-p);
  }
  bool in(const Point &a){
    return abs(a-p)<=r+eps;
  }
};
struct E{
  int u,v;
  R dst;
};
bool comp(E a,E b){return a.dst<b.dst;}
void SOLVE(){
  int n;
  cin>>n;
  vector<Point>a(n);
  rep(i,n){
    R x,y;
    cin>>x>>y;
    a[i]={x,y};
  }
  dsu uf(n);
  vector<E>edge;
  vector<vector<int>>to(n);
  vector<int>cnt(n,0);
  vector<bool>seen(n,false);
  rep(i,n-1)reps(j,i+1,n){
    R cu=abs(a[i]-a[j]);
    edge.push_back({i,j,cu});
  }
  sort(all(edge),comp);
  for(auto [u,v,dst]:edge){
    if(uf.same(u,v))continue;
    uf.merge(u,v);
    to[u].push_back(v);
    to[v].push_back(u);
    cnt[u]++,cnt[v]++;
    debug(u,v);
  }
  queue<int>que;
  rep(i,n)if(cnt[i]==1)que.push(i),debug(i);
  vector<pair<int,int>>ans;
  while(!que.empty()){
    int x=que.front();
    que.pop();
    for(auto i:to[x]){
      if(!seen[i]){
        if(--cnt[i]<=1){
          if(!seen[x]){
            ans.push_back({i+1,x+1});
            seen[x]=true;
            seen[i]=true;
          }
        }
      }
    }
  }
  cout<<ans.size()<<endl;
  for(auto i:ans)cout<<i<<endl;
}
0