CF1093D.Beautiful Graph

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an undirected unweighted graph consisting of nn vertices and mm edges.

You have to write a number on each vertex of the graph. Each number should be 11, 22 or 33. The graph becomes beautiful if for each edge the sum of numbers on vertices connected by this edge is odd.

Calculate the number of possible ways to write numbers 11, 22 and 33 on vertices so the graph becomes beautiful. Since this number may be large, print it modulo 998244353998244353.

Note that you have to write exactly one number on each vertex.

The graph does not have any self-loops or multiple edges.

你被给定一个由 nn 个顶点和 mm 条边构成的无向无权图。

你需要在图的每个顶点上写一个数字,该数字只能是 11、22 或 33。若对图中每条边,其两个端点上的数字之和均为奇数,则称该图为“优美的”。

请计算有多少种方式在顶点上写数字 11、22 和 33,使得该图变为优美的。由于答案可能很大,请输出其对 998244353998244353 取模的结果。

注意:每个顶点上必须且只能写一个数字。

该图不含自环或重边。

输入格式

The first line contains one integer tt (1≤t≤3⋅1051 \le t \le 3 \cdot 10^5) — the number of tests in the input.

The first line of each test contains two integers nn and mm (1≤n≤3⋅105,0≤m≤3⋅1051 \le n \le 3 \cdot 10^5, 0 \le m \le 3 \cdot 10^5) — the number of vertices and the number of edges, respectively. Next mm lines describe edges: ii-th line contains two integers uiu_i, $ v_i$ (1≤ui,vi≤n;ui≠vi1 \le u_i, v_i \le n; u_i \neq v_i) — indices of vertices connected by ii-th edge.

It is guaranteed that ∑i=1tn≤3⋅105\sum\limits_{i=1}^{t} n \le 3 \cdot 10^5 and ∑i=1tm≤3⋅105\sum\limits_{i=1}^{t} m \le 3 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤3⋅1051 \le t \le 3 \cdot 10^5)—— 输入中测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤3⋅105, 0≤m≤3⋅1051 \le n \le 3 \cdot 10^5,\ 0 \le m \le 3 \cdot 10^5)—— 分别表示顶点数和边数。接下来的 mm 行描述边:第 ii 行包含两个整数 uiu_i、viv_i(1≤ui,vi≤n; ui≠vi1 \le u_i, v_i \le n;\ u_i \neq v_i)—— 表示第 ii 条边所连接的两个顶点的编号。

保证 ∑i=1tn≤3⋅105\sum\limits_{i=1}^{t} n \le 3 \cdot 10^5 且 ∑i=1tm≤3⋅105\sum\limits_{i=1}^{t} m \le 3 \cdot 10^5。

输出格式

For each test print one line, containing one integer — the number of possible ways to write numbers 11, 22, 33 on the vertices of given graph so it becomes beautiful. Since answers may be large, print them modulo 998244353998244353.

对每组测试数据,输出一行,包含一个整数——即在给定图的顶点上填入数字 11、22、33 使其变为“优美图”的方案数。由于答案可能很大,请对 998244353998244353 取模后输出。

输入输出样例

  • 输入#1

    2
    2 1
    1 2
    4 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4

    输出#1

    4
    0

说明/提示

Possible ways to distribute numbers in the first test:

  1. the vertex 11 should contain 11, and 22 should contain 22;
  2. the vertex 11 should contain 33, and 22 should contain 22;
  3. the vertex 11 should contain 22, and 22 should contain 11;
  4. the vertex 11 should contain 22, and 22 should contain 33.

In the second test there is no way to distribute numbers.

第一次测试中数字的可能分配方式:

  1. 顶点 11 应包含 11,顶点 22 应包含 22;
  2. 顶点 11 应包含 33,顶点 22 应包含 22;
  3. 顶点 11 应包含 22,顶点 22 应包含 11;
  4. 顶点 11 应包含 22,顶点 22 应包含 33。

在第二次测试中,不存在可行的数字分配方式。

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

首页