CF1299D.Around the World

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Guy-Manuel and Thomas are planning 144144 trips around the world.

You are given a simple weighted undirected connected graph with nn vertexes and mm edges with the following restriction: there isn't any simple cycle (i. e. a cycle which doesn't pass through any vertex more than once) of length greater than 33 which passes through the vertex 11. The cost of a path (not necessarily simple) in this graph is defined as the XOR of weights of all edges in that path with each edge being counted as many times as the path passes through it.

But the trips with cost 00 aren't exciting.

You may choose any subset of edges incident to the vertex 11 and remove them. How many are there such subsets, that, when removed, there is not any nontrivial cycle with the cost equal to 00 which passes through the vertex 11 in the resulting graph? A cycle is called nontrivial if it passes through some edge odd number of times. As the answer can be very big, output it modulo 109+710^9+7.

Guy-Manuel 和 Thomas 正在计划环游世界的 144144 次旅行。

给定一个含 nn 个顶点和 mm 条边的简单带权无向连通图,满足如下限制条件:不存在长度大于 33 的、经过顶点 11 的简单环(即不重复经过任一顶点的环)。图中一条路径(不一定是简单路径)的代价定义为该路径中所有边的权重的 异或(XOR),其中每条边的权重在异或运算中出现的次数等于该路径经过该边的次数。

但代价为 00 的旅行并不令人兴奋。

你可以任选顶点 11 所关联的一组边并将其全部删除。问:有多少种这样的边子集,使得删除后所得图中不存在任何经过顶点 11 的、代价为 00 的非平凡环?若一个环经过某条边的次数为奇数,则称该环为非平凡环。由于答案可能非常大,请将结果对 109+710^9+7 取模后输出。

输入格式

The first line contains two integers nn and mm (1≤n,m≤1051 \le n,m \le 10^5) — the number of vertexes and edges in the graph. The ii-th of the next mm lines contains three integers aia_i, bib_i and wiw_i (1≤ai,bi≤n,ai≠bi,0≤wi<321 \le a_i, b_i \le n, a_i \neq b_i, 0 \le w_i \lt 32) — the endpoints of the ii-th edge and its weight. It's guaranteed there aren't any multiple edges, the graph is connected and there isn't any simple cycle of length greater than 33 which passes through the vertex 11.

第一行包含两个整数 nn 和 mm(1≤n,m≤1051 \le n,m \le 10^5),分别表示图中顶点和边的数量。接下来的 mm 行中,第 ii 行包含三个整数 aia_i、bib_i 和 wiw_i(1≤ai,bi≤n1 \le a_i, b_i \le n,ai≠bia_i \neq b_i,0≤wi<320 \le w_i \lt 32),表示第 ii 条边的两个端点及其权重。保证图中不存在重边,图是连通的,且不存在长度大于 33 且经过顶点 11 的简单环。

输出格式

Output the answer modulo 109+710^9+7.

以 109+710^9+7 为模输出答案。

输入输出样例

  • 输入#1

    6 8
    1 2 0
    2 3 1
    2 4 3
    2 6 2
    3 4 8
    3 5 4
    5 4 5
    5 6 6

    输出#1

    2
  • 输入#2

    7 9
    1 2 0
    1 3 1
    2 3 9
    2 4 3
    2 5 4
    4 5 7
    3 6 6
    3 7 7
    6 7 8

    输出#2

    1
  • 输入#3

    4 4
    1 2 27
    1 3 1
    1 4 1
    3 4 0

    输出#3

    6

说明/提示

The pictures below represent the graphs from examples. In the first example, there aren't any nontrivial cycles with cost 00, so we can either remove or keep the only edge incident to the vertex 11. In the second example, if we don't remove the edge 1−21-2, then there is a cycle 1−2−4−5−2−11-2-4-5-2-1 with cost 00; also if we don't remove the edge 1−31-3, then there is a cycle 1−3−2−4−5−2−3−11-3-2-4-5-2-3-1 of cost 00. The only valid subset consists of both edges. In the third example, all subsets are valid except for those two in which both edges 1−31-3 and 1−41-4 are kept.

下方图片展示了示例中的图。

在第一个示例中,不存在任何非平凡的零代价环(nontrivial cycles with cost 00),因此我们可以选择删除或保留唯一与顶点 11 关联的边。

在第二个示例中,若不删除边 1-21\text{-}2,则存在一个零代价环 1-2-4-5-2-11\text{-}2\text{-}4\text{-}5\text{-}2\text{-}1;同样,若不删除边 1-31\text{-}3,则存在一个零代价环 1-3-2-4-5-2-3-11\text{-}3\text{-}2\text{-}4\text{-}5\text{-}2\text{-}3\text{-}1。唯一合法的边子集即为同时包含这两条边的子集。

在第三个示例中,除同时保留边 1-31\text{-}3 和 1-41\text{-}4 的两个子集外,其余所有子集均合法。

输入解题思路,AI测评打分。不知道怎么写?

首页