您的位置:首页
Codeforces 91C Ski Base 加边求欧拉回路数量
2017-05-15 15:13
295 查看
题目链接:点击打开链接
题意:
给出n个点m条无向边的图
開始图里没有边。每次加一条边,然后输出图里欧拉回路的条数。
思路:
We will count the number of ski bases including the base consisted of empty subset of edges (before printing just subtract one). In the beginning the number of bases is equal to 1.
If we connect vertexes in the same connected components then the result should be multiplied by 2 else do nothing. You should use DJS data structure to know information
about connected components where vertexes are and to unite them.
Why is it correct?
To prove it we will use the matrix of incidence I, rows in it will be edges and columns will be vertexes. Let's define xor of
two rows. Xor of two rows a и b will
be row c such that ci = ai xor bi.
Notice if xor of some subset of rows is equal to a zero row then this subset form the ski base. It's correct because, the degree of contiguity of every
vertex is even, so we can form an Euler cycle in every connected component. The answer is 2(m - rank(I)).
Why it is correct? Let's write the number of edge from the right of each row which suit this row. While finding the matrix rank using gauss method with xor operation,
we will xor the subsets from the right of the strings. In the end the subsets of edges written from the right of the zero rows will form the basis of the
linear space. Thats why we can take any subset of vectors from basis and make up a new ski base. The number of these subsets is equal to 2k = 2(m - rank(I)),
where k is the number of zero rows.
The last thing we should notice that the adding row is liner depended if and only if there is exist a way between the vertexes a and b (aand b are
the ends of the adding edge).
题意:
给出n个点m条无向边的图
開始图里没有边。每次加一条边,然后输出图里欧拉回路的条数。
思路:
We will count the number of ski bases including the base consisted of empty subset of edges (before printing just subtract one). In the beginning the number of bases is equal to 1.
If we connect vertexes in the same connected components then the result should be multiplied by 2 else do nothing. You should use DJS data structure to know information
about connected components where vertexes are and to unite them.
Why is it correct?
To prove it we will use the matrix of incidence I, rows in it will be edges and columns will be vertexes. Let's define xor of
two rows. Xor of two rows a и b will
be row c such that ci = ai xor bi.
Notice if xor of some subset of rows is equal to a zero row then this subset form the ski base. It's correct because, the degree of contiguity of every
vertex is even, so we can form an Euler cycle in every connected component. The answer is 2(m - rank(I)).
Why it is correct? Let's write the number of edge from the right of each row which suit this row. While finding the matrix rank using gauss method with xor operation,
we will xor the subsets from the right of the strings. In the end the subsets of edges written from the right of the zero rows will form the basis of the
linear space. Thats why we can take any subset of vectors from basis and make up a new ski base. The number of these subsets is equal to 2k = 2(m - rank(I)),
where k is the number of zero rows.
The last thing we should notice that the adding row is liner depended if and only if there is exist a way between the vertexes a and b (aand b are
the ends of the adding edge).
#include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <algorithm> #include <iostream> #include <set> using namespace std; const int N = 100100; const int mod = 1000000009; int f ; int find(int x){ return x == f[x] ? x : f[x] = find(f[x]); } bool Union(int x, int y){ int fx = find(x), fy = find(y); if (fx == fy)return false; if (fx > fy)swap(fx, fy); f[fx] = fy; return true; } int n, m; int main(){ while (cin >> n >> m){ for (int i = 1; i <= n; i++)f[i] = i; int ans = 1; while (m--){ int u, v; scanf("%d %d", &u, &v); if (Union(u, v)==false) ans = (ans + ans) % mod; printf("%d\n", ans-1); } } return 0; }
相关文章推荐
- Codeforces 91C Ski Base 加边求欧拉回路数量
- Codeforces 429E Points and Segments 欧拉回路
- [欧拉回路 并查集] Codeforces 547D #305 (Div. 1) D. Mike and Fish
- CodeForces - 788B Weird journey(欧拉回路)
- [欧拉回路 构造 || 网络流] Codeforces 723E #375 (Div. 2) E. One-Way Reform
- codeforces 788B—— Weird journey(图论,组合,欧拉回路变形)详解
- CodeForces 209C Trails and Glades(欧拉回路判断+并查集计算联通分量)
- Codeforces 527E Data Center Drama(欧拉回路)
- CodeForces 527E Data Center Drama(欧拉回路)
- 【欧拉回路】 Codeforces 288 D Tanya and Password
- CodeForces 21D Traveling Graph 状压dp+欧拉回路
- CodeForces 723E -One-Way Reform 构造+ 欧拉回路
- 欧拉回路的一点研究与Codeforces 62D Wormhouse
- Codeforces-788B Weird journey(计数/欧拉回路)
- 【codeforces 519 D】【hash+dp】【给出一个字符串,给出每个字母的权值,求字符串的子串中首尾相等,除去首尾字母的权值和为0的数量。】
- Codeforces 723e [图论][欧拉回路]
- codeforces 723E. One-Way Reform(欧拉回路||网络流)
- 欧拉回路的一点研究与Codeforces 62D Wormhouse
- codeforces 51C(Three Base Stations)
- BaseServlet扩展了的HttpServlet,来实现减少Servlet数量