TouchStone
  Please Login
Login Sign Up
 Homepage  Problem Set  Examinations  Submissions  Discussions  Statistics
  • Home
  • Problem Set
  • P8442
  • Problem
  • P8442【CDQ】最小生成树
    Limits : Time Limit : - MS   Memory Limit : 524288 KB
    Judgment Tips : 原题2s(nkoj3s),512MB
    Description

    三维空间中给定 \(n\) 个点,在任意两点之间连一条边的代价为它们的曼哈顿距离,求最小生成树。

    Input Format

    第一行一个整数 \(n\)

    接下来 \(n\) 行,每行三个整数 \(x_i,y_i,z_i\) ,表示一个点的坐标。

    Output Format

    一个整数,表示最小生成树的所有边的代价之和。

    Sample Input 1

    4
    -4 -2 -4
    -5 2 -5
    1 3 -1
    3 9 -10

    Sample Output 1

    34

    Sample Input 2

    10
    -59548347 52727296 -78967231
    -62939611 -5059013 -99276485
    70464612 98660753 -10318941
    27335355 1214255 -90850436
    89269379 29258946 74945660
    29815267 -59231298 -76624350
    -20766645 -22102665 -5451141
    -69354355 73947421 -64901098
    75251403 -59076295 18364058
    -25724064 -7601155 91325246

    Sample Output 2

    1050967746

    Hint

    数据范围

    对于 \(20\%\) 的数据, \(n\leq 5\;000\)
    对于另外 \(30\%\) 的数据, \(n\leq 50\;000\)\(z_i=0\)
    对于另外 \(30\%\) 的数据, \(n\leq 50\;000\) ,保证坐标在 \([-10^8,10^8]\) 范围内均匀随机;
    对于 \(100\%\) 的数据, \(1\leq n\leq 50\;000\) ,坐标范围 \([-10^8,10^8]\)