Codeforces Round #306 (Div. 2) D. Regular Bridge 构造
2015-06-05 03:20
323 查看
D. Regular Bridge
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/contest/550/problem/DDescription
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.
[b]Input[/b]
The single line of the input contains integer k (1 ≤ k ≤ 100) — the required degree of the vertices of the regular graph.
[b]Output[/b]
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).
[b]Sample Input[/b]
1
Sample Output
YES2 1
1 2
HINT
[b]题意[/b]让你构造度数为k的正则图,然后要求里面至少有一条边是桥
[b]题解:[/b]
构造,乱搞……
构造出一个bra图……
[b]代码:[/b]
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 2000001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** int main() { int K; cin >>K; if(K%2==0) { cout << "NO"; return 0; } cout << "YES\n"; printf("%d %d\n", K*4-2, (K*4-2)*K/2); printf("%d %d\n", 1, (K*2-1)+1); for(int i = 2; i <= K; ++i) { printf("%d %d\n", 1, i); printf("%d %d\n", (K*2-1)+1, (K*2-1)+i); for(int j = K+1; j <= 2*K-1; ++j) { printf("%d %d\n", i, j); printf("%d %d\n", (K*2-1)+i, (K*2-1)+j); } } for(int i = K+1; i <= 2*K-1; i += 2) { printf("%d %d\n", i, i+1); printf("%d %d\n", (K*2-1)+i, (K*2-1)+i+1); } }
相关文章推荐
- Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
- Codeforces Round #306 (Div. 2) C
- Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs
- Codeforces Round #306 (Div. 2) B
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
- Java课程实验报告 实验三 敏捷开发与XP实践
- Codeforces Round #306 (Div. 2) A
- 线索二叉树
- 二叉树链式结构
- 二叉树顺序结构实现
- 模式匹配
- 串
- 链队列
- 顺序队列
- 斐波那契的递归函数
- 链栈
- React.js在ios设备上onClick事件失效的解决办法
- 两栈共享空间
- 顺序栈
- Maximum Product Subarray