当前位置 博文首页 > sky123博客:Codeforces Round #715 (Div. 2) F. Complete the M

    sky123博客:Codeforces Round #715 (Div. 2) F. Complete the M

    作者:[db:作者] 时间:2021-09-21 20:58

    题目链接
    As a teacher, Riko Hakozaki often needs to help her students with problems from various subjects. Today, she is asked a programming task which goes as follows.

    You are given an undirected complete graph with n n n nodes, where some edges are pre-assigned with a positive weight while the rest aren’t. You need to assign all unassigned edges with non-negative weights so that in the resulting fully-assigned complete graph the XOR sum of all weights would be equal to 0 0 0.

    Define the ugliness of a fully-assigned complete graph the weight of its minimum spanning tree, where the weight of a spanning tree equals the sum of weights of its edges. You need to assign the weights so that the ugliness of the resulting graph is as small as possible.

    As a reminder, an undirected complete graph with n n n nodes contains all edges ( u , v ) (u, v) (u,v) with 1 ≤ u < v ≤ n 1 \le u < v \le n 1u<vn; such a graph has n ( n ? 1 ) 2 \frac{n(n-1)}{2} 2n(n?1)? edges.

    She is not sure how to solve this problem, so she asks you to solve it for her.

    Input

    The first line contains two integers n n n and m m m ( 2 ≤ n ≤ 2 ? 1 0 5 2 \le n \le 2 \cdot 10^5 2n2?105, 0 ≤ m ≤ min ? ( 2 ? 1 0 5 , n ( n ? 1 ) 2 ? 1 ) 0 \le m \le \min(2 \cdot 10^5, \frac{n(n-1)}{2} - 1) 0mmin(2?105,2n(n?1)??1)) — the number of nodes and the number of pre-assigned edges. The inputs are given so that there is at least one unassigned edge.

    The i i i-th of the following m m m lines contains three integers u i u_i ui?, v i v_i vi?, and w i w_i wi? ( 1 ≤ u i , v i ≤ n 1 \le u_i, v_i \le n 1ui?,vi?n, u ≠ v u \ne v u?=v, 1 ≤ w i < 2 30 1 \le w_i < 2^{30} 1wi?<230), representing the edge from u i u_i ui? to v i v_i vi? has been pre-assigned with the weight w i w_i wi?. No edge appears in the input more than once.

    Output

    Print on one line one integer — the minimum ugliness among all weight assignments with XOR sum equal to 0 0 0.

    Examples

    input

    4 4
    2 1 14
    1 4 14
    3 2 15
    4 3 8
    

    output

    15
    

    input

    6 6
    3 6 4
    2 4 1
    4 5 7
    3 4 10
    3 5 1
    5 2 15
    

    output

    0
    

    input

    5 6
    2 3 11
    5 3 7
    1 4 10
    2 4 14
    4 3 8
    2 5 6
    

    output

    6
    

    Note

    The following image showcases the first test case. The black weights are pre-assigned from the statement, the red weights are assigned by us, and the minimum spanning tree is denoted by the blue edges.

    img
    显然,一定存在一种最优解,使得加入的边有一条为 ? i = 1 m w i \bigoplus \limits_{i=1}^mw_i i=1?m?w

    下一篇:没有了