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…
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…
题意:给定两个数,表示一个图的点数和边数,让你构造出一个图满足 1-  n 的最短路是素数,并且最小生成树也是素数. 析:首先 1 - n 的最短路,非常好解决,直接 1 连 n 就好了,但是素数尽量选小的,选2,3,5,这样比较小的,然后再构造MST,可以给每个边都是 1,然后最后 n-2 连 n-1的时候,保证加起来是素数就好,然后剩下的边随便连,凑够边数就好,但是权值要尽量的大,但不要超过1e9,一开始没看到 1e9,写大了,1e8就够用了. 代码如下: #pragma comment(l…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找比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…
Bubble Sort Graph CodeForces - 340D 题意: 给出一个n个数的数列,建一个只有n个结点没有边的无向图,对数列进行冒泡排序,每交换一对位置在(i,j)的数在点i和点j间连一条边.排序完后,求得到图的最大独立集. 解释: 最初想到的是图的最大独立集,认为不能解,于是就没辙了... 然而应当仔细分析题目(不容易想到):题意很容易知道是在每一对逆序对间连一条边.也就是说,对于a[i],向a[i]右侧比其小的和a[i]左侧比其大的都要连一条边.也就是说,只要选了结点i,那…
Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can…
D - Beautiful Graph CodeForces - 1093D You are given an undirected unweighted graph consisting of nn vertices and mm edges. You have to write a number on each vertex of the graph. Each number should be 11, 22or 33. The graph becomes beautiful if for…
思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上差分 ] | Codeforces Round #429(Div 1) 题意: 选择一个边集合,满足某些点度数的奇偶性 分析: 将d = 1的点连成一颗树,不在树上的点都不连边. 可以发现,当某个节点u的所有子节点si均可操控 (u, si) 来满足自身要求 即整棵树上至多只有1个点不满足自身要求,…