"Bzoj" 2115: [Wc2011] Xor

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=2115

Test instructions: Given a weighted graph of n-point m-Edge undirected connected edge, find a path of 1~n to make the XOR value maximum (can repeat the point can repeat the edge) (n<=50000, m<=100000)

#include <bits/stdc++.h>using namespace Std;const int n=50005, m=100015;typedef long long ll;struct E {int Next, to ; ll W; }e[m<<1];int CNT, ihead[n], tot, N, M;ll D[n], q[m*10], a[65];void Add (int u, int v, ll c) {e[++cnt]= (e) {Ihead[u], V , c}; Ihead[u]=cnt;e[++cnt]= (e) {ihead[v], u, c}; ihead[v]=cnt;} BOOL Vis[n];void DFS (int x) {vis[x]=1;for (int i=ihead[x]; i; i=e[i].next) if (!vis[e[i].to]) D[E[I].TO]=D[X]^E[I].W, DFS ( E[I].TO); else Q[++TOT]=D[E[I].TO]^D[X]^E[I].W;} int main () {scanf ("%d%d", &n, &m); for (int i=0; i<m; ++i) {int x, y; ll W; scanf ("%d%d%lld", &x, &y, &A MP;W); Add (x, Y, W); }dfs (1); for (int i=1, i<=tot; ++i) for (int j=60; j>=0;--j) if ((q[i]>>j) &1) {if (!a[j]) {a[j]=q[i]; else q[i]^=a[j];} ll ans=d[n];for (int j=60; j>=0;--j) if (! ( (ans>>j) &1) ans^=a[j];p rintf ("%lld\n", ans); return 0;}

 

A good question does not explain.

First, we learned a little bit about linear radicals. The linear basis here is defined here as the linear independent amount in a closed set formed by an XOR operation of a vector array. After we have found these bases, we can find the answer with a simple greed.

Then learn a special property = = The ring formed on the non-tree edge of the spanning tree can represent the XOR value of all the rings in the case of XOR (this yy has been proved for a long time and can only be verified by hand.) It is probably that every non-tree edge exists with a ring that is found, and then an XOR with some rings cancels out some of the tree edges and forms a new ring.

The upper bound of the number of bases is $o (log (n)) $

Then we only need to use Gaussian elimination to find a single element of each individual, then you can be a base, and finally there will be a set of bases ... The size is $o (log (n)), n is the size of the vector, which means that the highest bit of a base exists and no other base exists.

Because of the closeness of the XOR operation, we just need to eliminate the value of the other elements in the same way as the Gaussian elimination element.

Back to the subject ...

Because the path of a 1~n can be made up of any single 1~n simple path plus any ring. (The path to the loop from the simple path and the path of the outbound (same) XOR offset)

As previously mentioned, non-tree-side loops can linearly form the XOR value of all rings, so let's just do it ...

PS: eh ah ah yes must be strong pull to base ... The best thing to understand is that I want to be greedy, so I'm going to turn into some numbers so that the highest bit has only one number with no other number, and these numbers can be linearly combined into all the numbers that the previous vectors can make up. You say yes, SB Iwtwiioi a big version of what he doesn't understand.

"Bzoj" 2115: [Wc2011] Xor

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.