• bzoj2115: [Wc2011] Xor


    一道不知道讲过多少遍的线性基。

    发现路径一定是一条路径一条若干环拼成的。路径是什么无所谓,总能通过走一些环调整成其他路径。

    所以答案就是1到n的随意一条路径加若干环能异或出的最大值。如何找环,建出树,每一条非树边对应一个环。

    然后直接用线性基就可以了。

     1 //Achen
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<cstdio>
     7 #include<vector>
     8 #include<queue>
     9 #include<cmath>
    10 #define For(i,a,b) for(int i=(a);i<=(b);i++)
    11 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
    12 const int N=2e5+7;
    13 typedef long long LL;
    14 using namespace std;
    15 int n,m,tot;
    16 LL a[N],b[60];
    17 
    18 template<typename T> void read(T &x) {
    19     T f=1; x=0; char ch=getchar();
    20     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    21     if(ch=='-') f=-1,ch=getchar();
    22     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
    23 }
    24 
    25 int ecnt,fir[N],nxt[N],to[N],vis[N];
    26 LL val[N];
    27 void add(int u,int v,LL x) {
    28     nxt[++ecnt]=fir[u]; fir[u]=ecnt; to[ecnt]=v; val[ecnt]=x; 
    29     nxt[++ecnt]=fir[v]; fir[v]=ecnt; to[ecnt]=u; val[ecnt]=x;
    30 }
    31 
    32 LL R[N];
    33 void dfs(int x,int fa) {
    34     vis[x]=1;
    35     for(int i=fir[x];i;i=nxt[i]) if(to[i]!=fa) {
    36         if(!vis[to[i]]) {
    37             R[to[i]]=R[x]^val[i];
    38             dfs(to[i],x);
    39         }
    40         else a[++tot]=R[x]^R[to[i]]^val[i];
    41     }
    42 } 
    43 
    44 int main() {
    45 #ifdef DEBUG
    46     freopen("1.in","r",stdin);
    47     freopen("1.out","w",stdout);
    48 #endif
    49     read(n); read(m);
    50     For(i,1,m) {
    51         int x,y; LL d;
    52         read(x); read(y); read(d);
    53         add(x,y,d);
    54     }
    55     dfs(1,0);
    56     LL qs=R[n];
    57     For(i,1,tot)
    58         Rep(j,59,0) if(a[i]&(1LL<<j)) {
    59             if(!b[j]) { b[j]=a[i]; break; }
    60             else a[i]^=b[j];
    61         } 
    62     Rep(i,59,0) if((qs^b[i])>qs) qs^=b[i];
    63     printf("%lld
    ",qs);
    64     return 0;
    65 }
    66 /*
    67 5 7 
    68 1 2 2 
    69 1 3 2 
    70 2 4 1 
    71 2 5 1 
    72 4 5 3 
    73 5 3 4 
    74 4 3 2
    75 */ 
    View Code
  • 相关阅读:
    mysql 5.7修改密码
    使用zfs进行pg的pitr恢复测试
    什么是构造函数?它和普通函数的区别?
    匿名函数和普通函数的区别
    http缓存机制
    全局变量和局部变量
    什么是web语义化?
    ajax状态值和状态码
    如何理解MVVM?
    如果理解&&运算符和各类数值的布尔值
  • 原文地址:https://www.cnblogs.com/Achenchen/p/8693555.html
Copyright © 2020-2023  润新知