Kingdom Connectivity

평면 직선 그래프에서 각 벽의 비용이 주어질 때, 모든 벽의 양쪽이 외부에서 접근 가능하도록 문을 설치할 벽의 최소 비용 집합을 구한다.

어려움8그래프최소 신장 트리기하유니온 파인드아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You 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 nn towers and mm 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:

  • no wall connects a tower to itself;
  • there can be at most one wall between any pair of towers;
  • different walls do not intersect anywhere except at the towers;
  • no two towers have the same position;
  • no wall can pass through any towers other than its endpoints.

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 nn, mm --- the number of towers and and the number of walls respectively (1n,m1051 \leq n, m \leq 10^5).

Each of the next nn lines contains two integers x_ix\_i, y_iy\_i, denoting that the ii-th tower is to be built at the point (x_i,y_i)(x\_i, y\_i). Coordinates do not exceed 10610^6 by absolute value.

Each of the next mm lines contains three integers u_iu\_i, v_iv\_i, c_ic\_i (1u_i,v_in1 \leq u\_i, v\_i \leq n, 1c_i1061 \leq c\_i \leq 10^6), denoting that there will be a wall between towers u_iu\_i and v_iv\_i and the price of building a gate through this wall is c_ic\_i.

출력

First, print a single number: minimum amount of money needed to build all necessary gates. Then print a number kk, the number of gates to be built. Then print kk pairs of numbers denoting pairs of towers which are connected by walls with gates according to your plan.