D. Relatively Prime Graph
Let's call an undirected graph G=(V,E)G=(V,E) relatively prime if and only if for each edge (v,u)∈E(v,u)∈E GCD(v,u)=1GCD(v,u)=1 (the greatest common divisor of vv and uu is 11). If there is no edge between some pair of vertices vv and uu then the value of GCD(v,u)GCD(v,u) doesn't matter. The vertices are numbered from 11 to |V||V|.
Construct a relatively prime graph with nn vertices and mm edges such that it is connected and it contains neither self-loops nor multiple edges.
If there exists no valid graph with the given number of vertices and edges then output "Impossible".
If there are multiple answers then print any of them.
The only line contains two integers nn and mm (1≤n,m≤1051≤n,m≤105) — the number of vertices and the number of edges.
If there exists no valid graph with the given number of vertices and edges then output "Impossible".
Otherwise print the answer in the following format:
The first line should contain the word "Possible".
The ii-th of the next mm lines should contain the ii-th edge (vi,ui)(vi,ui) of the resulting graph (1≤vi,ui≤n,vi≠ui1≤vi,ui≤n,vi≠ui). For each pair (v,u)(v,u)there can be no more pairs (v,u)(v,u) or (u,v)(u,v). The vertices are numbered from 11 to nn.
If there are multiple answers then print any of them.
5 6
Possible
2 5
3 2
5 1
3 4
4 1
5 4
6 12
Impossible
Here is the representation of the graph from the first example:
这题无脑暴力 暴力真的出了奇迹
暴力枚举一遍就行了
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
const int INF = 0x3fffffff;
typedef long long LL;
using namespace std;
int n, m;
struct node {
int x, y;
node () {}
node (int x, int y): x(x), y(y) {}
} qu[maxn];
int main() {
scanf("%d%d", &n, &m);
if (n - > m) {
printf("Impossible\n");
return ;
}
int k = , flag = ;
for (int i = ; i <= n ; i++) {
for (int j = i + ; j <= n ; j++) {
if (__gcd(i, j) == ) qu[k++] = node(i, j);
if (k == m) {
flag = ;
break;
}
}
if (flag) break;
}
if (flag) {
printf("Possible\n");
for (int i = ; i < k ; i++)
printf("%d %d\n", qu[i].x, qu[i].y);
} else printf("Impossible\n");
return ;
}
D. Relatively Prime Graph的更多相关文章
- Codeforces 1009D:Relatively Prime Graph
D. Relatively Prime Graph time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Relatively Prime Graph CF1009D 暴力 思维
Relatively Prime Graph time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Global Round 4 Prime Graph CodeForces - 1178D (构造,结论)
Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wan ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- CodeForces - 1009D Relatively Prime Graph
题面在这里! 直接暴力找点对就行了,可以证明gcd=1是比较密集的,所以复杂度略大于 O(N log N) #include<bits/stdc++.h> #define ll long ...
- Educational Codeforces Round 47 (Rated for Div. 2) :D. Relatively Prime Graph
题目链接:http://codeforces.com/contest/1009/problem/D 解题心得: 题意就是给你n个点编号1-n,要你建立m条无向边在两个互质的点之间,最后所有点形成一个连 ...
- 【Codeforces 1009D】Relatively Prime Graph
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 1000以内就有非常多组互质的数了(超过1e5) 所以,直接暴力就行...很快就找完了 (另外一开始头n-1条边找1和2,3...n就好 [代 ...
- CF1178D Prime Graph
题目链接 题意 构造一张有\(n(3\le n\le 1000)\)个点的无向图(无重边和自环).满足: 边的总数为素数 所有点的度数均为素数 输出方案 solution 如果所有点的度数确定了.那么 ...
- Codeforces 1178D. Prime Graph
传送门 首先每个点至少要有两条边连接 那么容易想到先保证这一点然后再慢慢加边 那么先构成一个环即可:$(1,2),(2,3),(3,4)...(n,1)$ 然后考虑加边,发现一个点加一条边还是合法的, ...
随机推荐
- 通过SVI实现VLAN间通信
两个不同网段的计算机与三层交换机直连,通过SVI实现VLAN间通信vlan 1 //几个不同网段就创建几个VLANvlan 2 int f0/1 //划分VLANswitchport mode acc ...
- 单片机C51 8位流水灯
#include<reg51.h> sbit P1_0=0X90; sbit P1_1=0x91; sbit P1_2=0x92; sbit P1_3=0x93; sbit P1_4=0x ...
- python2.7入门---字典(Dictionary)
这次咱们记录的是python中的字典这个鬼,首先我们得了解,字典是另一种可变容器模型,且可存储任意类型对象.字典的每个键值 key=>value 对用冒号 : 分割,每个键值对之间用逗号 ...
- python2.7练习小例子(二十七)
27):题目:一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同. #!/usr/bin/python # -*- coding: UTF-8 -* ...
- 通过py2exe打包python程序的过程中,解决的一系列问题
py2exe的使用方法参考<py2exe使用方法>. 注:程序可以在解释器中正常运行,一切问题都出在打包过程中. 问题1: 现象:RuntimeError: maximum recursi ...
- ajax设置自定义头
一.setting参数 headers $.ajax({ headers: { Accept: "application/json; charset=utf-8" ...
- jdk带的一些工具,强悍
这些工具有的已经接触到了,功能很强悍,但是使用也有点复杂(参数) 在代码中使用System.setProperty()或者在启动程序时使用-D选项设置代理服务器地址和端口 看看别人的研究: JDK自带 ...
- 【个人笔记】关于C++小数的处理
无论是C-Style还是C++-Style的输出,小数都会四舍五入.如果想要截断两种比较好的方法.第一种:利用sscanf输出成字符串,再人为地putchar().第二种:已知钦定保留6位小数,那么可 ...
- Windows Server 2008 R2(x64) IIS7+PHP5(FastCGI)环境搭建
相关软件下载: 1.PHP下载地址: http://windows.php.net/downloads/releases/php-5.4.4-nts-Win32-VC9-x86.zip 如果是win2 ...
- 九度OJ--1167(C++)
#include <iostream>#include <algorithm>#include <map> using namespace std; int mai ...