Submission #906678

# Submission time Handle Problem Language Result Execution time Memory
906678 2024-01-14T17:06:17 Z vjudge1 Odašiljači (COCI20_odasiljaci) C++17
35 / 70
268 ms 26528 KB
#include <bits/stdc++.h>
using namespace std;

#define fastIO()                     \
  ios_base::sync_with_stdio(false);  \
  cin.tie(NULL);                     \
  cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define allr(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvi = vector<vector<int>>;
using vvpii = vector<vector<pair<int, int>>>;
const int MOD = (int)1e9 + 7;

struct Edge{
  long double w;
  ll a1, b1, a2, b2;

  bool operator<(const Edge & o) {
    return w < o.w;
  }

  void calculate_dist(){
    w = (abs(a1-b1)*abs(a1-b1)) + (abs(a2-b2)*abs(a2-b2));
    w = sqrt(w);
  }
};

int n;  
vector<pll> node;
vector<Edge> adj;

struct DSU {
  map<pll, pll> p;
  map<pll, ll> rank;

  DSU() {
    for (int i=0; i < n; i++) {
      p.insert({node[i], node[i]});
      rank.insert({node[i], 1});
    }
  }

  pll find(pll v) {
    return ( v == p[v]) ? v : p[v] = find(p[v]);
  }

  void unite(pll a, pll b) {
    a = find(a);
    b = find(b);

    if (a == b) return;

    if (rank[a] < rank[b]) swap(a, b);
    p[b] = a;
    if (rank[a] == rank[b]) rank[a]++;
  }
};

long double kruskal() {
  sort(all(adj));
  long double max_edge = adj[0].w;
  DSU dsu;

  for (auto[w,a1,b1,a2,b2] : adj) {
    if (dsu.find({a1, a2}) == dsu.find({b1, b2}))
      continue;
    dsu.unite({a1, a2} , {b1, b2});
    max_edge = max(max_edge, w);
  }

  return max_edge / 2;
}


int main() {
  fastIO();

  ll x, y;

  cin >> n;
  
  node.resize(n);
  for (int i=0; i < n; i++) {
    cin >> x >> y;
    node[i] = {x, y};
  }

  for (int i=0; i < n; i++)
    for (int j=i+1; j < n; j++) {
      Edge e = {0, node[i].ff, node[j].ff, node[i].ss, node[j].ss};
      e.calculate_dist();
      adj.pb(e);
    }

  cout << kruskal();

  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Correct 1 ms 604 KB Output is correct
4 Incorrect 2 ms 604 KB Output isn't correct
5 Correct 2 ms 800 KB Output is correct
6 Correct 51 ms 7884 KB Output is correct
7 Correct 57 ms 7884 KB Output is correct
8 Incorrect 135 ms 26308 KB Output isn't correct
9 Correct 268 ms 25284 KB Output is correct
10 Incorrect 265 ms 26528 KB Output isn't correct