D. Regular Bridge
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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).
Examples
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-1个点
然后底下再多两个点
每个点都连那k-1个点
然后多出来的俩互联
偶数不行就是因为没法处理中间那k-1个
其实很早就想到加两个点了
但是没考虑到奇数偶数
所以忽略过去了
是个教训…
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int k;
void shuchu(int tou, int wei)
{
int nayiquan = k - 1;
for (int a = tou;a <= wei - 3;a++)
{
for (int b = a;b <= wei - 3;b++)
{
if (a == b||abs(a-b)==(k-1)/2)continue;
cout << a << " " << b << endl;
}
cout << a << " " << wei - 1<<endl;
cout << a<<" " << wei - 2 << endl;
cout << a << " " << wei << endl;
}
cout << wei - 1 << " " << wei - 2 << endl;
}
int main()
{
cin >> k;
if (k == 1)
{
cout << "YES"<<endl;
cout << "2 1" << endl<<"2 1"<<endl;
return 0;
}
if (k == 2)
{
cout << "NO" << endl;
return 0;
}
if (k == 3)
{
cout << "YES" << endl;
cout << "10 15" << endl;
cout << "1 2" << endl << "1 3" << endl << "1 4" << endl << "2 4" << endl;
cout << "3 2" << endl << "4 5" << endl << "3 5" << endl << "5 10" << endl;
cout << "10 6" << endl << "10 7" << endl << "6 9" << endl << "6 8" << endl;
cout << "7 8" << endl << "7 9" << endl << "8 9" << endl;
return 0;
}
if (k % 2 == 0)
{
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
cout << 2 * k+4 << " " << 2*(3*(k-1)+1+((k-3)/2)*(k-1))+1 << endl;
cout << k+2 << " " << 2*k + 4<<endl;
shuchu(1, k + 2);
shuchu(k + 3, 2 * k + 4);
return 0;
}

本文探讨了如何构建至少包含一个桥边的连接且k-正则的无向图,针对不同k值提供了具体的解决方案,特别是对于奇数和偶数k的情况进行了深入分析。

被折叠的 条评论
为什么被折叠?



