Codeforces 91C Ski Base addition edge Euler's number of circuits
Question:
Returns n vertices and m undirected edges.
Start to merge without edges, add an edge each time, and then output the number of Euler loop.
Ideas:
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 shocould be multiplied by 2 else do nothing. you shoshould 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 incidenceI, Rows in it will be edges and columns will be vertexes. Let's defineXorOf two rows.XorOf two rowsABytesBWill be rowCSuch thatCISignature = SignatureAIXorBI. Notice ifXorOf 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 (MAccept-Encoding-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 methodXorOperation, we willXorThe 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 (MAccept-Encoding-Rank(I), Where k is the number of zero rows.
The last thing we shoshould notice that the adding row is liner depended if and only if there is exist a way between the vertexesAAndB(AAndBAre the ends of the adding edge ).
#include
#include
#include
#include
#include #include
#include
using namespace std;const int N = 100100; const int mod = 1000000009;int f[N];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, ans-1);}}return 0;}