Codeforces 550D. Regular Bridge Construction

Source: Internet
Author: User

Codeforces 550D. Regular Bridge Construction

 

For a graph, the degrees of each vertex are K and at least one bridge is required.

Constructor:

When k is an odd number, a solution is provided to construct such a graph. The Left Group has k + 1 points, and the right group has k + 1 points. The center goes through m1, m2 is connected to a bridge.

 

If the left and right sides of a complete graph are left and right, the degrees of each vertex are k. Now we want to connect them through m1 and m2 without changing the degrees.

 

Obviously, this figure is symmetric. We only consider m1 on the left and m2 as A bridge, and m1 and m2 are connected to an edge. m1 and A point on the left must be connected together, another edge is connected. At this time, the degree of vertex A is too high. We need to break an edge from the other vertex B in the group. In order to keep the degree of vertex B unchanged, B will connect another edge to m1, at this time, the degree of m1 is at least 3, and then the degree of m1 is completed. each time you delete an edge from the Left Group, you can connect the two points of the edge to m1. the degree of m1 increases by 2 each time, so if k is an odd number, it can be constructed using this method.

 

 

 

D. Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

An undirected graph is calledK-Regular, if the degrees of all its vertices are equalK. 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 undirectedK-Regular graph containing at least one bridge, or else state that such graph doesn' t exist.

Input

The single line of the input contains integerK(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 numbersNAndM-The number of vertices and edges respectively.

Each of the nextMLines must contain two integers,AAndB(1? ≤?A,?B? ≤?N,A? ?B), That mean that there is an edge connecting the verticesAAndB. 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 equalK. 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 ).

Sample test (s) input
1
Output
YES2 11 2
Note

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



 

 

import java.util.*;import java.math.*;public class Main{int k,midl,midr;boolean[][] edge = new boolean[330][330];boolean[] used = new boolean[330];void cut_and_link(int from,int to,int goal){int tk=k-3;while(tk>0){boolean flag=false;for(int i=from;i<to&&flag==false;i++) {="" if(used[i]="=true)" continue;="" for(int="" j="i+1;j
 
  

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.