# Graph Count Codechef Solution

## Graph Count Solution Problem Code: GRCNT

You are given an undirected graph with NN nodes and MM edges. There are exactly K=N(N−1)2−MK=N(N−1)2−M unordered pairs (i,j)(i,j) such that the edge (i,j)(i,j) is not present in the graph. For each of these pairs, you can choose whether to add the edge (i,j)(i,j) to the graph. Out of all 2K2K ways, find the number of ways in which each vertex has degree 22 in the final graph.

Since the answer can be large, print it modulo 998 244 353998 244 353.

### Input

• The first line contains an integer TT, the number of test cases. Then the test cases follow.
• The first line of each test case contains two integers NN, MM, the number of nodes and the number of edges in the graph.
• Each of the next MM lines contains two space-separated integers uu, vv, denoting an edge between nodes uu and vv in the graph.

### Output:

For each testcase, output in a single line, the number of ways in which all nodes of the final graph have degree 22, modulo 998 244 353998 244 353.

### Constraints

• 1≤T≤10001≤T≤1000
• 0≤M≤N≤3⋅1050≤M≤N≤3⋅105
• 1≤N1≤N
• 1≤u,v≤N1≤u,v≤N, u≠vu≠v
• There is at most one edge between the same pair of nodes.
• The sum of NN over all test cases does not exceed 3⋅1053⋅105

• Subtask 1 (10 points): T≤10T≤10, N≤11N≤11
• Subtask 2 (15 points): T≤10T≤10, N≤40N≤40
• Subtask 3 (25 points): T≤10T≤10, N≤350N≤350
• Subtask 4 (30 points): The sum of NN over all test cases does not exceed 50005000
• Subtask 5 (25 points): Original constraints

### Sample Input

``````3
4 3
1 4
3 2
2 4
4 4
1 2
2 3
1 3
1 4
6 0
``````

### Sample Output

``````1
0
70
``````

### Explanation

In the first test case, there is only one valid way: adding an edge between 11 and 33.

In the second test case, there is no valid way.

Program:

``````
import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{

int testCount = Integer.parseInt(br.readLine());

for (int t = 0 ; t < testCount; t++) {

int N = Integer.parseInt(br.readLine());

int [] digits = new int[N];
String [] str = new String[N];

StringTokenizer st = new StringTokenizer(br.readLine());

boolean hasOdd = false;
int oddIndex = -1;

for (int i = 0 ; i < N ; i++) {

int d = Integer.parseInt(st.nextToken());

if (d % 2 != 0 && !hasOdd) {
hasOdd = true;
oddIndex = i;
}
digits[i] = d;
str[i] = d + "";
}

if (digits[N-1] % 2 == 0 && hasOdd) {

String temp = str[oddIndex];
str[oddIndex] = str[N-1];
str[N-1] = temp;
}

String result = String.join(" ", str);

System.out.println(result);

}

}

}
``````