题目链接: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. Servlet和SpringMVC补课

    1.web.xml加载顺序 http://mianhuaman.iteye.com/blog/1105522 关键点:ServletContext -> context-param -> ...

  2. github的初步认识

    第一部分:我用代码写了一个简单的可以运行的helloworld代码. 其链接为:https://github.com/ljw305503/CK01.git 第二部分:GitHub是一个分布式的版本控制 ...

  3. c++下各种编码格式转换的方法

    1.利用c++11新特性 std::wstring_convert配合std::codecvt模板类 作者:Gomo Psivarh链接:https://www.zhihu.com/question/ ...

  4. typescript 添加基础类型的扩展方法

    以时间转换为案例: //声明接口,也是在声明date这个基础类型要定义一个format的扩展方法,不写接口声明会报错 interface Date { Format(fmt:string):strin ...

  5. 初学Pollard Rho算法

    前言 \(Pollard\ Rho\)是一个著名的大数质因数分解算法,它的实现基于一个神奇的算法:\(MillerRabin\)素数测试(关于\(MillerRabin\),可以参考这篇博客:初学Mi ...

  6. 去除a标签的下划线

    a:link ,a:visited,a:hover,a:active { text-decoration: none;}

  7. Python-time和datetime模块

    一.time模块 1.表示时间的三种方式 >>> import time >>> time.time() #当前时间戳 1509525556.8485825 > ...

  8. 使用Vue做评论+localStorage存储(js模块化)

    未分模块化 html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...

  9. js正则判断日期

    //****************************************************************************// Function ID : Commo ...

  10. 【luogu P3627 [APIO2009]抢掠计划】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3627 把点权转化到边权上去. #include <stack> #include <que ...