http://codeforces.com/problemset/problem/862/B 题意: 给出一个有n个点的二分图和n-1条边,问现在最多可以添加多少条边使得这个图中不存在自环,重边,并且此图还是一个二分图. 思路: 想得比较复杂了....其实既然已经给出了二分图并且有n-1条边,那么我们就一定可以用染色法对每一个点进行染色,从而将点划分为两个集合,然后从两个集合中分别任意选择一个点连边就行了. 一开始考虑二分图的基本属性是不存在奇数条边的环...并不需要这样,因为两个集合是分开的,…
862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) ; bool color[N]; vector<int>g[N]; ; int…
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \(n\) 序列 \(A\),和 \(q\) 次询问,对于每一次询问给出两个数 \(l, x\) ,你需要计算在前缀和 \(A[1, l]\) 中选取若干个数,使得它们 \(xor\) 起来的结果等于 \(x\) 的方案数 $n , q \leq 10^5   0 \leq A_i \leq 2^{20} $…
 Mahmoud and Ehab and the bipartiteness Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose verti…
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in su…
\(\color{#0066ff}{题目描述}\) 给出n个点,n-1条边,求再最多再添加多少边使得二分图的性质成立 \(\color{#0066ff}{输入格式}\) The first line of input contains an integer n - the number of nodes in the tree ( \(1<=n<=10^{5}\) ). The next n−1 lines contain integers u and v ( \(1<=u,v<=…
题意:给定一个n个点的树,该树同时也是一个二分图,问最多能添加多少条边,使添加后的图也是一个二分图. 分析: 1.通过二分图染色,将树中所有节点分成两个集合,大小分别为cnt1和cnt2. 2.两个集合间总共可以连cnt1*cnt2条边,给定的是一个树,因此已经连了n-1条边,所以最多能连cnt1*cnt2-(n-1)条边. 3.注意输出. #include<cstdio> #include<cstring> #include<cstdlib> #include<…
Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of the same length such that: b is lexicographically greater than or equal to a. bi ≥ 2. b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are c…
Discription Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex …
题目链接:http://codeforces.com/contest/862/problem/C 题解:一道简单的构造题,一般构造题差不多都考自己脑补,脑洞一开就过了 由于数据x只有1e5,但是要求是1e6,而且我们知道3个数可以组合成任意数也就是说n-3的数从1-1e5直接任意找然后使得其总xor为sum 当sum=x时(定义Max=1<<17 > 1e5)那么这三个数只要组成0就行,当sum!=x时那么这三个数只要构成sum^x就行,这3个数从1e5~1e6中找 很好找的. #inc…