Codeforces 91C Ski Base plus edge for Euler circuit number

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions

gives a graph of n-point M-bar without a forward edge

There is no edge in the start diagram, one edge at a time, and then output the number of the Euler loop in the graph.

Ideas:

We'll 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 are equal to1. If we connect vertexes in the same connected and the result should be multiplied by2else do nothing. You should use DJS data structure to know information about connected the where vertexes is and to unite them.

Why is it correct?
To prove it we'll use the matrix of incidenceI, rows in it would be edges and columns would be vertexes. Let ' s defineXORof the rows.Xorof the rowsaИb'll be rowCsuch that Ci? =? a I Xor bi . 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 a Euler cycle in every connected C Omponent. The answer is2(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 withXOROperation, we'llXORThe subsets from the right of the strings. In the end of the subsets of edges written, the right of the zero rows would form the basis of the linear space. Thats why we can take any subset of the vectors from basis and make up a new ski base. The number of these subsets is equal to2k =2(m?-? Rank(I)), where k is the number of zero rows.


The last thing we should notice, the adding row is liner depended if and only if there is exist a, the between EXEs 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[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;r Eturn 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 plus edge for Euler circuit number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.