Contents
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
Subtasks
- 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
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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);
}
}
}
Weekly Contest 247
- Maximum Product Difference Between Two Pairs
- Cyclically Rotating a Grid
- Number of Wonderful Substrings
- Count Ways to Build Rooms in an Ant Colony
Biweekly Contest 55
- Remove One Element to Make the Array Strictly Increasing
- Remove All Occurrences of a Substring
- Maximum Alternating Subsequence Sum
- Design Movie Rental System
June Long Challenge 2021 Solutions
- Maximum Frequent Subarray Sum solution codechef
- Dual Distance solution codechef
- Optimal Xor Set solution codechef
- Minimum Subtree Cover solution codechef
- Minimum Dual Area solution codechef
- Bitwise Tuples solution codechef
- Shortest Route solution codechef
- Bella ciao solution codechef
- Summer Heat solution codechef
March Long Challenge 2021 Solutions
- An Interesting Sequence ISS SOLUTION
- Tree House THOUSES SOLUTION
- Valid Paths VPATH SOLUTION
- Modular Equation MODEQ SOLUTION
- Tic Tac Toe TCTCTOE SOLUTION
- Xor Equality XOREQUAL SOLUTION
- Golf LKDNGOLF SOLUTION
- Solubility SOLBLTY SOLUTION
April Long Challenge 2021 Solutions
- Chef and Dice SDICE Solution
- Worthy Matrix KAVGMAT Solution
- Binary String MEX MEXSTR Solution
- Boolean Game BOOLGAME Solution
- Tree Permutations TREEPERM Solution
- Destroy the EMP Chip CHAOSEMP Solution
- Chef and Pair Flips PAIRFLIP Solution
- String Power STRPOW Solution
- Brahma and Shiva SHRINES Solution
- Water Sort Puzzle (Challenge) WTRSORT Solution
- World Record BOLT Solution
- Strong Language SSCRIPT Solution
- Valid Pair SOCKS1 Solution
Codechef Long Challenge Solutions
February Long Challenge 2021
- 1. Frog Sort Solution Codechef
- 2. Chef and Meetings Solution Codechef
- 3. Maximise Function Solution Codechef
- 4. Highest Divisor Solution Codechef
- 5. Cut the Cake Challenge Solution Codechef
- 6. Dream and the Multiverse Solution Codechef
- 7. Cell Shell Solution Codechef
- 8. Multiple Games Solution Codechef
- 9. Another Tree with Number Theory Solution Codechef
- 10. XOR Sums Solution Codechef
- 11. Prime Game Solution CodeChef
- 12. Team Name Solution Codechef
January Long Challenge 2021
- Chef and Division 3 DIVTHREE SOLUTION Code Chef
- Encoded String DECODEIT SOLUTION Code Chef
- Point Of Impact BILLRD SOLUTION Code Chef
- Fair Elections FAIRELCT SOLUTION Code Chef
- Watching CPL WIPL SOLUTION Code Chef
- Chef and Ants ANTSCHEF SOLUTION Code Chef
- Blackjack BLKJK SOLUTION Code Chef
- And-Or Game ORAND SOLUTION Code Chef
- Stack-Queue Sort (Challenge) SQSORT SOLUTION Code Chef
- Expected Number of SCCs RCTEXSCC SOLUTION Code Chef
- Curious Matrix CURMAT SOLUTION Code Chef
- Cool Subsets COOLSBST SOLUTION Code Chef
- Sequence Creation ARCRT SOLUTION Code Chef
- Greedy Students GRDSTD SOLUTION Code Chef
November Challenge 2020 SOLUTION CodeChef
- Ada and Dishes SOLUTION ADADISH
- Iron Magnet and Wall SOLUTION FEMA2
- Magical Candy Store SOLUTION CNDYGAME
- Unusual Queries SOLUTION UNSQUERS
- Red-Black Boolean Expression SOLUTION RB2CNF
- Chef and the Combination Lock SOLUTION CHEFSSM
- Scalar Product Tree SOLUTION SCALSUM
- Connect on a Grid (Challenge) SOLUTION CONGRID
October Lunchtime 2020 CodeChef SOLUTIONS
- AND Plus OR SOLUTION ANDOR
- Chef and Subtree MEXs SOLUTION SUBMEXS
- Chef Likes Good Sequences SOLUTION GSUB
- Cute Chef Gift SOLUTION COPAR
- Chef Is Just Throwing Random Words SOLUTION SSO
- Counting Spaghetti SOLUTION CDSUMS
- Chef and Edge Flipping SOLUTION EFLIP
Related :
- A. Shandom Ruffle SOLUTION
- B. Pear TreaP SOLUTION
- C. Sneetches and Speeches 3 SOLUTION
- D. The Grim Treaper SOLUTION
- Y. Sneetches and Speeches 1 SOLUTION
- Z. Trick or Treap SOLUTION
- A. Floor Number SOLUTION CODE FORCES
- B. Symmetric Matrix SOLUTION CODE FORCES
- C. Increase and Copy SOLUTION CODE FORCES
- D. Non-zero Segments SOLUTION CODE FORCES
- E. Rock, Paper, Scissors SOLUTION CODE FORCES
- F. Number of Subsequences SOLUTION CODE FORCES
Related :
- Chef and Easy Queries SOLUTIONS CHEFEZQ
- Covid Run SOLUTIONS CVDRUN OCTOBER CHALLENGE
- Positive AND SOLUTIONS POSAND
- Replace for X SOLUTIONS REPLESX
- Village Road Network SOLUTIONS VILLNET
- Random Knapsack SOLUTIONS RANDKNAP
- D-Dimensional MST SOLUTIONS DDIMMST
- Compress all Subsegments SOLUTIONS SEGCOMPR
- Adding Squares SOLUTIONS ADDSQURE
- Inversions SOLUTIONS INVSMOD2 OCOTBER CHALLENGE
- Rooted Minimum Spanning Tree SOLUTIONS ROOTMST