题目链接:http://codeforces.com/contest/1009/problem/D

解题心得:

  • 题意就是给你n个点编号1-n,要你建立m条无向边在两个互质的点之间,最后所有点形成一个连通图。
  • 首先要明白n个点要形成连通图至少需要n-1条边,然后就是找边了,看了一下n和m的范围都是1e5,总感觉自己暴力能过,写了暴力过了,迷茫。。。。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+; vector <pair<int,int> > ve;
int n,m; void init() {
scanf("%d%d",&n,&m);
} void Print() {
if(m < n-) {
printf("Impossible\n");
return ;
}
printf("Possible\n");
for(int i=;i<ve.size();i++) {
pair <int,int> P = ve[i];
printf("%d %d\n",P.first, P.second);
}
} int main() {
init();
int cnt = ;
for(int i=;i<=n;i++) {
for(int j=i+;j<=n;j++) {
if(__gcd(i, j) == ) {
ve.push_back(make_pair(i, j));
cnt++;
}
if(cnt == m) {
Print();
return ;
}
}
}
printf("Impossible");
return ;
}

Educational Codeforces Round 47 (Rated for Div. 2) :D. Relatively Prime Graph的更多相关文章

  1. Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph

    D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...

  2. Educational Codeforces Round 47 (Rated for Div. 2) :E. Intercity Travelling

    题目链接:http://codeforces.com/contest/1009/problem/E 解题心得: 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是 ...

  3. Educational Codeforces Round 47 (Rated for Div. 2) :C. Annoying Present(等差求和)

    题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一 ...

  4. Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String

    题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就 ...

  5. Educational Codeforces Round 47 (Rated for Div. 2) :A. Game Shopping

    题目链接:http://codeforces.com/contest/1009/problem/A 解题心得: 题意就是给你两个数列c,a,你需要从c中选择一个子串从a头开始匹配,要求子串中的连续的前 ...

  6. Educational Codeforces Round 47 (Rated for Div. 2) 题解

    题目链接:http://codeforces.com/contest/1009 A. Game Shopping 题目: 题意:有n件物品,你又m个钱包,每件物品的价格为ai,每个钱包里的前为bi.你 ...

  7. Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency

    E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...

  8. Educational Codeforces Round 55 (Rated for Div. 2):C. Multi-Subject Competition

    C. Multi-Subject Competition 题目链接:https://codeforces.com/contest/1082/problem/C 题意: 给出n个信息,每个信息包含专业编 ...

  9. Educational Codeforces Round 47 (Rated for Div. 2)E.Intercity Travelling

    题目链接 大意:一段旅途长度N,中间可能存在N-1个休息站,连续走k长度时,疲劳值为a1+a2+...+aka_1+a_2+...+a_ka1​+a2​+...+ak​,休息后a1a_1a1​开始计, ...

随机推荐

  1. 【Leetcode】【Easy】Min Stack

    Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...

  2. JS教程之实现加载图片时百分比进度

    思路:思路其实很简单,ajax执行时,会生成一个event对象,其中会包含要加载的文件的大小和当前已经加载完成部分的大小,通过这两个值即可计算出百分比 事件介绍onprogress 当浏览器正在加载媒 ...

  3. Perl 基础笔记: 使用 cpanm 安装 Perl 模块

    cpanm 其实只是一个可执行文件而已.将它下载到 bin 目录,然后添加执行权限就可以用了. $ sudo wget http://xrl.us/cpanm -O /usr/bin/cpanm; s ...

  4. 用C++实现HTTP服务器 - Windows平台(开放源代码)

    有时间了看一下 https://blog.csdn.net/querw/article/details/6593328 libevent也实现了一下http服务

  5. Android笔记之 图片自由裁剪

    前言--项目中须要用到对用户头像的裁剪和上传功能.关于裁剪.一開始是想自己来做,可是认为这个东西应该谷歌有开发吧,于是一搜索官方文档.果然有.于是.就果断无耻地用了Android自带有关于照片的自由裁 ...

  6. BZOJ2648/2716:SJY摆棋子/[Violet]天使玩偶(K-D Tree)

    Description 这天,SJY显得无聊.在家自己玩.在一个棋盘上,有N个黑色棋子.他每次要么放到棋盘上一个黑色棋子,要么放上一个白色棋子,如果是白色棋子,他会找出距离这个白色棋子最近的黑色棋子. ...

  7. unbuntu循环登录

    http://www.myexception.cn/operating-system/1707766.html

  8. 【luogu P4114 Qtree1】 题解

    题目链接:https://www.luogu.org/problemnew/show/P4114 1.把边权转化到点权:选取连接这条边的两个点中较深的一个. 2.查询点到点之间的边权时,要从seg[x ...

  9. centOS 7 更改root密码

    Linux忘记密码怎么办,不用重装系统,进入emergency mode 更改root密码即可. 首先重启系统,按下 向下 按钮, 定位在第一个,摁 e ,进行编辑 找到 ro , 把ro改为 rw ...

  10. vim_preview_window

    *29.2*    The preview window When you edit code that contains a function call, you need to use the c ...