GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday, 14 May 2022

[Solution] Formalism for Formalism Codeforces Solution | Codeforces Problem Solution 2022

F. Formalism for Formalism
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Yura is a mathematician, and his cognition of the world is so absolute as if he have been solving formal problems a hundred of trillions of billions of years. This problem is just that!

Consider all non-negative integers from the interval [0,10n). For convenience we complement all numbers with leading zeros in such way that each number from the given interval consists of exactly n decimal digits.

Solution Click Below:-  CLICK HERE

You are given a set of pairs (ui,vi), where ui and vi are distinct decimal digits from 0 to 9.

Consider a number x consisting of n digits. We will enumerate all digits from left to right and denote them as d1,d2,,dn. In one operation you can swap digits di and di+1 if and only if there is a pair (uj,vj) in the set such that at least one of the following conditions is satisfied:

  1. di=uj and di+1=vj,
  2. di=vj and di+1=uj.


We will call the numbers x and y, consisting of n digits, equivalent if the number x can be transformed into the number y using some number of operations described above. In particular, every number is considered equivalent to itself.

You are given an integer n and a set of m pairs of digits (ui,vi). You have to find the maximum integer k such that there exists a set of integers x1,x2,,xk (0xi<10n) such that for each 1i<jk the number xi is not equivalent to the number xj.

Input

The first line contains an integer n (1n50000) — the number of digits in considered numbers.

The second line contains an integer m (0m45) — the number of pairs of digits in the set.

Each of the following m lines contains two digits ui and vi, separated with a space (0ui<vi9).

It's guaranteed that all described pairs are pairwise distinct.

Output

Print one integer — the maximum value k such that there exists a set of integers x1,x2,,xk (0xi<10n) such that for each 1i<jk the number xi is not equivalent to the number xj.

As the answer can be big enough, print the number k modulo 998244353.

Join Now for Solution:- 

No comments:

Post a Comment