Advertisement
Romanchenko

problem420

Nov 7th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct pt
  6. {
  7.     int x;
  8.     int y;
  9. };
  10.  
  11. const int INF = 1e9;
  12.  
  13. struct edge
  14. {
  15.     int v;
  16.     int u;
  17.     int w;
  18.     bool operator < (edge q)
  19.     {
  20.         return w < q.w;
  21.     }
  22. };
  23.  
  24. int sqr(int t)
  25. {
  26.     return t * t;
  27. }
  28.  
  29. int dist(pt a, pt b)
  30. {
  31.     return sqr(a.x - b.x) + sqr(a.y - b.y);
  32. }
  33.  
  34.  
  35. int main()
  36. {
  37.     ios_base::sync_with_stdio(false);
  38.     cin.tie(0);
  39.     //freopen("input.txt", "r", stdin);
  40.     int n;
  41.     cin >> n;
  42.     vector<pt> a(n);
  43.     for (int i = 0; i < n; i++)
  44.         cin >> a[i].x >> a[i].y;
  45.     vector< pair<int, int> > d(n, {INF, -1});
  46.     vector<int> used(n, 0);
  47.     vector<int> clr(n, 0);
  48.     d[0] = {0, -1};
  49.     clr[0] = 0;
  50.     int ans = INF;
  51.     for (int i = 0; i < n; i++)
  52.     {
  53.         int mn = -1;
  54.         for (int j = 0; j < n; j++)
  55.         {
  56.             if (!used[j] && (mn == -1 || (d[j].first < d[mn].first)))
  57.                 mn = j;
  58.         }
  59.         int u = mn;
  60.         int v = d[mn].second;
  61.         used[u] = 1;
  62.         clr[u] = 1 - clr[v];
  63.         for (int j = 0; j < n; j++)
  64.         {
  65.             if (used[j])
  66.                 continue;
  67.             if (dist(a[u], a[j]) < d[j].first)
  68.                 d[j] = {dist(a[u], a[j]), u};
  69.         }  
  70.     }
  71.    
  72.     for (int i = 0; i < n; i++)
  73.     {
  74.         for (int j = i + 1; j < n; j++)
  75.             if (clr[i] == clr[j])
  76.                 ans = min(ans, dist(a[i], a[j]));
  77.     }
  78.  
  79.  
  80.     cout << fixed << setprecision(10) << sqrt(ans / (double)4) << endl;
  81.     for (auto x : clr)
  82.         cout << x + 1 << " ";
  83.     return 0;  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement