1. 程式人生 > >cf550D Regular Bridge

cf550D Regular Bridge

upper star ati %d color queue truct eas itl

Regular Bridge

An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.

Build a connected undirected k-regular graph containing at least one bridge, or else state that such graph doesn‘t exist.

Input

The single line of the input contains integer k (1?≤?k?≤?100) — the required degree of the vertices of the regular graph.

Output

Print "NO" (without quotes), if such graph doesn‘t exist.

Otherwise, print "YES" in the first line and the description of any suitable graph in the next lines.

The description of the made graph must start with numbers n and m — the number of vertices and edges respectively.

Each of the next m lines must contain two integers, a and b (1?≤?a,?b?≤?n, a?≠?b), that mean that there is an edge connecting the vertices a and b. A graph shouldn‘t contain multiple edges and edges that lead from a vertex to itself. A graph must be connected, the degrees of all vertices of the graph must be equal k

. At least one edge of the graph must be a bridge. You can print the edges of the graph in any order. You can print the ends of each edge in any order.

The constructed graph must contain at most 106 vertices and 106 edges (it is guaranteed that if at least one graph that meets the requirements exists, then there also exists the graph with at most 106 vertices and at most 106 edges).

Example

Input
1
Output
YES
2 1
1 2

Note

In the sample from the statement there is a suitable graph consisting of two vertices, connected by a single edge.

題意是要搞出個無向圖,至少包含一條邊是橋,而且每個點度數都是k

顯然方便的構造是橋的兩邊是對稱的

假如有兩個聯通塊A,B通過一個橋聯通,那麽A和B之間除了橋以外不能有其他邊。

考慮A塊,假設有n個點,除去有一個點連出去一個橋,A塊中其他邊帶來的度數之和應當是nk-1。

顯然一條邊一次帶來2的度數,那麽nk-1是偶數,nk是奇數,n、k都是奇數。

因此對於k是偶數的肯定無解

然後就是瞎雞兒構造時間(不過為什麽我看標答的點比我構造的少這麽多)

假設A塊的s點連了橋,那麽s還需要連恰好k-1個點,標號成1~k-1,因為k是奇數所以k-1是偶數

然後對k-1個點兩兩分組,每組兩個點a,b現在都只和s連上,再新建k-1個點,a和b都分別和k-1個新點連上,這樣a和b度數都是k

新的k-1個點再兩兩連上變成完全圖,這樣每個新點都和k-2個其他新點連上,加上a和b恰好度數為k

技術分享
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<deque>
 9 #include<set>
10 #include<map>
11 #include<ctime>
12 #define LL long long
13 #define inf 0x7ffffff
14 #define pa pair<int,int>
15 #define mkp(a,b) make_pair(a,b)
16 #define pi 3.1415926535897932384626433832795028841971
17 #define mod 100007
18 using namespace std;
19 inline LL read()
20 {
21     LL x=0,f=1;char ch=getchar();
22     while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
23     while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
24     return x*f;
25 }
26 int k,n,m;
27 inline void put(int a,int b)
28 {
29     printf("%d %d\n%d %d\n",a,b,a+n/2,b+n/2);
30 }
31 int main()
32 {
33     k=read();
34     if (k%2==0){puts("NO");return 0;}
35     puts("YES");
36     n=2*(k+(k-1)/2*(k-1));m=2*(k-1+(k-1)/2*((k-1)+k*(k-1)/2))+1;
37     printf("%d %d\n1 %d\n",n,m,1+n/2);
38     
39     for (int i=2;i<=k;i++)put(1,i);
40     int cnt=k;
41     for (int i=1;i<=(k-1)/2;i++)
42     {
43         for (int j=1;j<k;j++)
44         {
45             put(1+i,++cnt);
46             put(1+(k-1)/2+i,cnt);
47         }
48         for (int j=cnt-k+2;j<=cnt;j++)
49             for (int l=j+1;l<=cnt;l++)
50                 put(j,l);
51     }
52 }
cf 550D

cf550D Regular Bridge