题意:给定两个数,表示一个图的点数和边数,让你构造出一个图满足 1-  n 的最短路是素数,并且最小生成树也是素数. 析:首先 1 - n 的最短路,非常好解决,直接 1 连 n 就好了,但是素数尽量选小的,选2,3,5,这样比较小的,然后再构造MST,可以给每个边都是 1,然后最后 n-2 连 n-1的时候,保证加起来是素数就好,然后剩下的边随便连,凑够边数就好,但是权值要尽量的大,但不要超过1e9,一开始没看到 1e9,写大了,1e8就够用了. 代码如下: #pragma comment(l…
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)) /*c…
http://codeforces.com/problemset/problem/916/C 好尬的题啊... #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back typed…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找比n-1大的最小的素数x 1-2,2-3..(n-2)-(n-1)长度都为1 然后(n-1)-n长度为(x-(n-2)) 然后其他边长度都设为x+1就好了. 这样就能满足题意了. [代码] #include <bits/stdc++.h> #define ll long long using namespace std; int n,m,ma; bool is(int x){ if (x<2) return false…
思路:构造 实现: #include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; cout << "100003 100003" << endl; ; i < n - ; i++) { cout << i + << << << endl; } cout <<…
E. Interesting Graph and Apples 题目连接: http://www.codeforces.com/contest/9/problem/E Description Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph a…
Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m\) 个联通块的有标号生成树的数量是 \[ n^{m-2}\prod_{i=1}^msize_i \] 其中 \(size_i\) 是第 \(i\) 个联通块的大小. 原理就是考虑 \(prufer\) 编码,先把每个联通块看成一个点,那么序列中每出现一个第 \(i\) 联通块缩成的点,能连的边的数…
链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到偶数的需要把区间内出现过的数字不重复的再异或一遍.离线按右端点排序,每次处理一个区间时,如果该数字出现过,则在树状数组中把这个数删去,再重新再该位置加到树状数组中. 代码…
Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就没啥难度了... #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #defin…
Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will sur…