fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-6
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. using namespace std;
  28. // mylittledoge
  29.  
  30. typedef long double dbl;
  31.  
  32. int main() {
  33. cin.sync_with_stdio(0);
  34. cin.tie(0);
  35. int N;
  36. cin >> N;
  37. vector< pair<int,int> > T(N);
  38. for(int i =0; i < N; i++) cin >> T[i].ff >> T[i].ss;
  39. vector< vector<int> > G(N);
  40. int M;
  41. cin >> M;
  42. for(int i =0; i < M; i++) {
  43. int a,b;
  44. cin >> a >> b;
  45. G[--a].push_back(--b);
  46. G[b].push_back(a);}
  47.  
  48. vector<bool> F(N,true);
  49. vector<dbl> D(N,1e10);
  50. vector<int> ako(N,0);
  51. F[0] =false;
  52. for(int i =1; i < N; i++) D[i] =sqrt(1.0L*(T[i].ff-T[0].ff)*(T[i].ff-T[0].ff)+1.0L*(T[i].ss-T[0].ss)*(T[i].ss-T[0].ss));
  53. ALL_THE(G[0],it) D[*it] =0;
  54. vector< pair<int,int> > ans;
  55. for(int i =1; i < N; i++) {
  56. int x =0;
  57. dbl d =1e10;
  58. for(int j =1; j < N; j++) if(F[j] && D[j] < d) {
  59. d =D[j];
  60. x =j;}
  61. if(d > 0.5) ans.push_back(make_pair(x+1,ako[x]+1));
  62. F[x] =false;
  63. ALL_THE(G[x],it) D[*it] =0, ako[*it] =x;
  64. for(int j =1; j < N; j++) if(F[j]) {
  65. d =sqrt(1.0L*(T[j].ff-T[x].ff)*(T[j].ff-T[x].ff)+1.0L*(T[j].ss-T[x].ss)*(T[j].ss-T[x].ss));
  66. if(d < D[j]) D[j] =d, ako[j] =x;}
  67. }
  68.  
  69. ALL_THE(ans,it) cout << it->ff << " " << it->ss << "\n";
  70. return 0;}
  71.  
  72. // look at my code
  73. // my code is amazing
Runtime error #stdin #stdout #stderr 0s 4460KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc