916C - Jamie and Interesting Graph

思路:构造。

对于1到n最短路且素数,那么1到n之间连2

对于最小生成树,找一个稍微大点的素数(比1e5大)构造一个和为这个素数的最小生成树

剩下的边都连1e9

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) /*const int N=1e5+5;
const int M=1e7+7;
vector<int>vc;
bool not_prime[M];
void prime(){
for(int i=2;i<M;i++){
if(!not_prime[i])vc.pb(i);
for(int j=0;i*vc[j]<M;j++){
not_prime[i*vc[j]]=true;
if(i%vc[j]==0)break;
}
}
cout<<vc[vc.size()-1]<<endl;//9999991
}*/
int main(){
ios::sync_with_stdio(false);
cin.tie();
//prime();
int n,m,t=;
cin>>n>>m;
if(n==)cout<<<<' '<<<<endl;
else cout<<<<' '<<t<<endl;
cout<<<<' '<<n<<' '<<<<endl;
t-=;
for(int i=;i<n;i++){
if(i!=n-)cout<<<<' '<<i<<' '<<<<endl,t-=;
else cout<<<<' '<<i<<' '<<t<<endl;
}
m-=n-;
for(int i=;i<=n;i++){
if(m==)break;
for(int j=i+;j<=n;j++){
if(m==)break;
cout<<i<<' '<<j<<' '<<<<endl;
m--;
if(m==)break;
}
if(m==)break;
}
return ;
}

Codeforces 916C - Jamie and Interesting Graph的更多相关文章

  1. CodeForces 916C Jamie and Interesting Graph (构造)

    题意:给定两个数,表示一个图的点数和边数,让你构造出一个图满足 1-  n 的最短路是素数,并且最小生成树也是素数. 析:首先 1 - n 的最短路,非常好解决,直接 1 连 n 就好了,但是素数尽量 ...

  2. Jamie and Interesting Graph CodeForces - 916C

    http://codeforces.com/problemset/problem/916/C 好尬的题啊... #include<cstdio> #include<algorithm ...

  3. 【Codeforces Round #457 (Div. 2) C】Jamie and Interesting Graph

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找比n-1大的最小的素数x 1-2,2-3..(n-2)-(n-1)长度都为1 然后(n-1)-n长度为(x-(n-2)) 然后其他 ...

  4. CF916C Jamie and Interesting Graph

    思路:构造 实现: #include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n ...

  5. Codeforces 1109D. Sasha and Interesting Fact from Graph Theory

    Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m ...

  6. Codeforces Beta Round #9 (Div. 2 Only) E. Interesting Graph and Apples 构造题

    E. Interesting Graph and Apples 题目连接: http://www.codeforces.com/contest/9/problem/E Description Hexa ...

  7. Codeforces 703D Mishka and Interesting sum 离线+树状数组

    链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ...

  8. Codeforces 1109D Sasha and Interesting Fact from Graph Theory (看题解) 组合数学

    Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就 ...

  9. Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 排列组合,Prufer编码

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF1109D.html 题意 所有边权都是 [1,m] 中的整数的所有 n 个点的树中,点 a 到点 b 的距离 ...

随机推荐

  1. -webkit-line-clamp超过两行就出现省略号

    -webkit-line-clamp 是一个 不规范的属性(unsupported WebKit property),它没有出现在 CSS 规范草案中. 限制在一个块元素显示的文本的行数. 为了实现该 ...

  2. CATiledLayer

    CATiledLayer 有些时候你可能需要绘制一个很大的图片,常见的例子就是一个高像素的照片或者是地球表面的详细地图.iOS应用通畅运行在内存受限的设备上,所以读取整个图片到内存中是不明智的.载入大 ...

  3. MyBatis学习笔记(三)——优化MyBatis配置文件中的配置

    转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4264301.html 一.连接数据库的配置单独放在一个properties文件中 之前,我们是直接将数据库的 ...

  4. pycharm中内看内建函数的定义

    鼠标方法在内建函数上,Ctrl+B,看内建函数的定义 如果想要看内置函数的具体实现细节,可以到python的lib目录下C:\Python27\Lib\,或者python的官网上 如果要看非内建的函数 ...

  5. python 处理xml

    XML XML指可扩展标记语言(Extensible Markup Language) XML被设计用于结构化.存储和传输数据 XML是一种标记语言,很类似于HTML XML没有像HTML那样 ...

  6. js 操作数字类型

    1.内置函数 Number().parseInt().parseFloat() var num = "88.88abc888"; Number(num);              ...

  7. where T : class含义

    .NET支持的类型参数约束有以下五种: where T : struct                               | T必须是一个结构类型where T : class       ...

  8. Starting MySQL...The server quit without updating PID file [失败]local/mysql/data/localhost.localdomain.pid报错

    在添加命令自动补全的时候mysql启动失败 这是原配 # For advice on how to change settings please see # http://dev.mysql.com/ ...

  9. 20145332 《网络攻防》 逆向与Bof实验

    20145332 <网络攻防>逆向与Bof实验 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用 ...

  10. 【源码编译】spark源码编译

    本文采用cdh版本spark-1.6.0-cdh5.12.0 1.源码包下载 2.进入根目录编译,编译的方式有2种 maven mvn clean package \ -DskipTests -Pha ...