#P10682. [COTS 2024] 奇偶南瓜 Tikvani

    ID: 12177 远端评测题 500ms 1024MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2024O2优化线性代数线性基COCI(克罗地亚)

[COTS 2024] 奇偶南瓜 Tikvani

Background

Translated from Izborne Pripreme 2024 (Croatian IOI/CEOI Team Selection) D1T3。0.5s,1G\texttt{0.5s,1G}

Problem Description

Given a directed graph G=(V,E)G=(V,E), where V=N,E=M|V|=N,|E|=M, it satisfies that for all (u,v)E(u,v)\in E, we have u<vu\lt v

Define an edge coloring scheme as a way to assign a 0/10/1 weight to each edge. Let the weight of edge (u,v)(u,v) be w(u,v)w(u,v)

Define a path from node uu to node vv as a sequence (a1,a2,,ak)(a_1,a_2,\cdots,a_k) such that a1=u,ak=va_1=u,a_k=v, and for all 1i<k1\le i\lt k, we have (ai,ai+1)E(a_i,a_{i+1})\in E。Define the weight of a path as the sum of the weights of all edges on it, i.e., i=1k1w(ai,ai+1)\displaystyle \sum_{i=1}^{k-1} w(a_{i},a_{i+1})

A coloring scheme is called good if and only if for every pair (u,v)(u,v), the remainders modulo 22 of the weights of all paths between (u,v)(u,v) are the same.

Compute the number of good coloring schemes, modulo (109+7)(10^9+7)

Input Format

The first line contains two positive integers N,MN,M, with meanings as described above。

The next MM lines each contain two positive integers u,vu,v, indicating (u,v)E(u,v)\in E

Output Format

Output one line with one integer, representing the result modulo (109+7)(10^9+7)

4 4
1 2
2 3
3 4
1 4
8
4 4
1 3
1 4
2 3
2 4
16

Hint

Sample Explanation

Explanation for sample 11: Obviously, only between 11 and 44 are there two paths (1,2,3,4),(1,4)(1,2,3,4),(1,4)

When w(1,4)=0w(1,4)=0, on the path (1,2,3,4)(1,2,3,4) you can only choose 00 or 22 edges whose weights are 11, so the number of schemes is 44

When w(1,4)=1w(1,4)=1, on the path (1,2,3,4)(1,2,3,4) you can only choose 11 or 33 edges whose weights are 11, so the number of schemes is 44

Therefore, the answer is 88

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1N4001\le N\le 4000M4000\le M\le 400
  • 1u<vn1\le u\lt v\le n
Subtask ID Score Constraints
11 2121 N6N \leq 6
22 2020 N13N \leq 13
33 3737 N,M50N, M \leq 50
44 2222 No additional constraints

Translated by ChatGPT 5