#P11055. Yet another ZP problem

Yet another ZP problem

Problem Description

There are nn points arranged from left to right, numbered 1,2,,n1,2,\dots,n.

You need to add some edges between them, and denote the edge set as E={(x,y)  1x<yn}E=\{(x,y)\ |\ 1\leq x<y\leq n\}.

We say that the edge set EE satisfies the constraint [l,r][l,r] if and only if there exists (x,y)E(x,y)\in E such that [x[l,r]]+[y[l,r]]=1[x\in[l,r]]+[y\in[l,r]]=1.

Basically, we require that for all 1in1\leq i\leq n, the constraint [i,i][i,i] is satisfied.

On top of that, the input gives mm additional constraints [li,ri][l_i,r_i] (1li<rin1\leq l_i<r_i\leq n and [li,ri][1,n][l_i,r_i]\neq [1,n]).

What is the minimum possible E|E|? Also, based on that, output one valid construction. It can be proven that a valid EE always exists.

For an expression of the form [P][P], its value is 11 if and only if the proposition PP is true; otherwise, its value is 00.

Input Format

The first line contains two integers n,mn,m.

The next mm lines each contain two positive integers li,ril_i,r_i.

Output Format

The first line output one number representing E|E|.

The next E|E| lines each contain two numbers x,yx,y representing an edge. Note that you must ensure 1x<yn1\le x<y\le n.

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

Hint

Sample Explanation

For the constraint [1,1][1, 1], there is an edge (1,4)(1, 4) such that [1[1,1]]+[4[1,1]]=1[1 \in [1, 1]] + [4 \in [1, 1]] = 1.

For the constraint [3,4][3, 4], there is an edge (1,4)(1, 4) such that [1[3,4]]+[4[3,4]]=1[1 \in [3, 4]] + [4 \in [3, 4]] = 1.

For the constraint [2,2][2, 2], there is an edge (2,3)(2, 3) such that [2[2,2]]+[3[2,2]]=1[2 \in [2, 2]] + [3 \in [2, 2]] = 1.

Constraints

For all testdata, it is guaranteed that 3n1043\leq n\leq 10^4, 0m1050\leq m\leq 10^5, 1li<rin1\le l_i<r_i\le n, and [li,ri][1,n][l_i,r_i]\ne [1,n].

Test Point ID Special Property
151\sim 5 n,m5n,m\le 5
676\sim 7 m=0m=0
8118\sim 11 ri<li+1r_i<l_{i+1}
121412\sim 14 li=1l_i=1
152015\sim 20 None

For the ii-th test point, it is guaranteed that the parity of nn is the same as the parity of ii, and the parity of mm is the same as the parity of i2+1\lfloor\frac{i}{2}\rfloor+1.

Translated by ChatGPT 5