日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

D. Relatively Prime Graph

發布時間:2023/12/18 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.

Input

The only line contains two integers?nn?and?mm?(1n,m1051≤n,m≤105) — the number of vertices and the number of edges.

Output

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 (1vi,uin,viui1≤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.

Examples input Copy 5 6 output Copy Possible
2 5
3 2
5 1
3 4
4 1
5 4 input Copy 6 12 output Copy Impossible Note

Here is the representation of the graph from the first example:

?

? ?這題無腦暴力 暴力真的出了奇跡?

? ?暴力枚舉一遍就行了

?

? ??

1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5 + 10; 4 const int INF = 0x3fffffff; 5 typedef long long LL; 6 using namespace std; 7 int n, m; 8 struct node { 9 int x, y; 10 node () {} 11 node (int x, int y): x(x), y(y) {} 12 } qu[maxn]; 13 int main() { 14 scanf("%d%d", &n, &m); 15 if (n - 1 > m) { 16 printf("Impossible\n"); 17 return 0; 18 } 19 int k = 0, flag = 0; 20 for (int i = 1 ; i <= n ; i++) { 21 for (int j = i + 1 ; j <= n ; j++) { 22 if (__gcd(i, j) == 1) qu[k++] = node(i, j); 23 if (k == m) { 24 flag = 1; 25 break; 26 } 27 } 28 if (flag) break; 29 } 30 if (flag) { 31 printf("Possible\n"); 32 for (int i = 0 ; i < k ; i++) 33 printf("%d %d\n", qu[i].x, qu[i].y); 34 } else printf("Impossible\n"); 35 return 0; 36 }

?

轉載于:https://www.cnblogs.com/qldabiaoge/p/9314221.html

總結

以上是生活随笔為你收集整理的D. Relatively Prime Graph的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。