Under construction

Still being built. Things may change

Planar Max Cut

Time limit7sMemory limit512 MB

Summary
Given a planar graph with a fixed straight-line embedding and edge costs, split the vertices into two sets so the total cost of edges crossing between them is maximized.
Level

Hard8 of 10

Topics
Graph, Dynamic programming, Divide and conquer
Solved
No attempts yet

Problem

Some of you may know how to find a minimum cut in a graph. Some of you may also know that the maximum cut problem is NP-complete (more precisely, the decision version of finding a cut of value at least kk is NP-complete). For some restricted classes of graphs, however, the problem is easier than in the general case.

Consider the Planar Maximum Cut problem. You are given an undirected graph GG with nn vertices and mm edges, where V={v1,…,vn}V = \{v_1, \dots, v_n\}. The graph is planar, and its embedding is given: the coordinates of every vertex are known, and when the edges are drawn as segments, no two edges share an internal point. Edge jj has an integer cost cjc_j.

Partition the vertices into two disjoint sets AA and BB (A∪B=VA \cup B = V) so that the total cost of the cut edges is maximized. An edge is a cut edge if one of its endpoints is in AA and the other is in BB.

Input

The first line contains two integers nn and mm (1≤n≤2001 \le n \le 200, 1≤m≤10001 \le m \le 1000).

Each of the next nn lines contains two integers xix_i and yiy_i (−104≤xi,yi≤104-10^4 \le x_i, y_i \le 10^4), the coordinates of vertex ii. No two points coincide.

Each of the next mm lines contains three integers aja_j, bjb_j, and cjc_j (1≤aj,bj≤n1 \le a_j, b_j \le n, aj≠bja_j \ne b_j, 0≤cj≤1050 \le c_j \le 10^5). This means edge jj connects vertices aja_j and bjb_j and has cost cjc_j.

Output

Print the maximum total cost of the cut edges on the first line.

On the second line, print nn integers s1,s2,…,sns_1, s_2, \dots, s_n. Print si=0s_i = 0 if vertex ii is in AA, and si=1s_i = 1 if vertex ii is in BB. If several answers exist, print any of them.

Examples1

  1. Example 1

    Input
    4 5
    0 0
    2 0
    0 2
    2 2
    1 2 3
    2 4 6
    3 4 4
    1 3 7
    2 3 8
    
    Expected output
    21
    0 0 1 1