평면 직선 그래프에서 각 벽의 비용이 주어질 때, 모든 벽의 양쪽이 외부에서 접근 가능하도록 문을 설치할 벽의 최소 비용 집합을 구한다.
어려움8그래프최소 신장 트리기하유니온 파인드아직 제출이 없습니다시간 제한2초메모리 제한512 MBYou are an engineer under the king's command. The king asked you to build a castle. The project is almost finished. It is already known that the castle is to contain n towers and m walls, each wall connecting some pair of towers. The towers can be viewed as points in the plane, and walls as segments connecting towers. The plan satisfies a number of sensible assumptions:
Your task is to select some walls and build gates in them. After that, both sides of every wall of the castle must be accessible from the exterior through gates. Different landscape imposes that you must spend different amounts of money to build gates through different wall. What is the minimum possible amount of money needed to accomplish your task?
First line contains two numbers n, m --- the number of towers and and the number of walls respectively (1≤n,m≤105).
Each of the next n lines contains two integers x_i, y_i, denoting that the i-th tower is to be built at the point (x_i,y_i). Coordinates do not exceed 106 by absolute value.
Each of the next m lines contains three integers u_i, v_i, c_i (1≤u_i,v_i≤n, 1≤c_i≤106), denoting that there will be a wall between towers u_i and v_i and the price of building a gate through this wall is c_i.
First, print a single number: minimum amount of money needed to build all necessary gates. Then print a number k, the number of gates to be built. Then print k pairs of numbers denoting pairs of towers which are connected by walls with gates according to your plan.