线性基+dfs树

我们先搞出dfs树,其实最终路径就是最初的路径和一些环异或。

环最多只有m-n+1,因为一共有m条边,然后有n-1条边在dfs树上,所以还剩m-n+1条边,都可以构成环。

所以dfs搞出环,线性基找最大值就可以了。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> PII;
const int N = ;
int n, m, cnt;
vector<PII> G[N];
ll a[N], d[N];
int used[N];
void gauss()
{
int now = ;
for(int i = ; i >= ; --i)
{
bool flag = false;
for(int j = now; j <= cnt; ++j)
if(a[j] & (1ll << i))
{
swap(a[j], a[now]);
flag = true;
break;
}
if(!flag) continue;
for(int j = ; j <= cnt; ++j) if((a[j] & (1ll << i)) && j != now)
a[j] ^= a[now];
++now;
}
--now;
}
void dfs(int u, int last)
{
used[u] = ;
for(int i = ; i < G[u].size(); ++i)
{
PII x = G[u][i];
int v = x.first;
ll w = x.second;
if(v == last) continue;
if(!used[v])
{
d[v] = d[u] ^ w;
dfs(v, u);
}
else a[++cnt] = d[v] ^ d[u] ^ w;
}
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = ; i <= m; ++i)
{
int u, v;
ll w;
scanf("%d%d%lld", &u, &v, &w);
G[u].push_back(make_pair(v, w));
G[v].push_back(make_pair(u, w));
}
dfs(, );
ll ans = d[n];
gauss();
for(int i = ; i <= && i <= cnt; ++i) if((ans ^ a[i]) > ans)
ans ^= a[i];
printf("%lld\n", ans);
return ;
}

最新文章

  1. linux命令二
  2. 【P1915】[usaco09 dec gold]电视游戏问题
  3. mysql分页原理和高效率的mysql分页查询语句
  4. BZOJ3172 后缀数组
  5. MVC权限管理系统dwpro项目分配按钮没有显示的问题
  6. CentOS搭建LAMP环境
  7. @(报错)could not find the main class, Program will exit(已解决)
  8. CareerCup chapter 1 Arrays and Strings
  9. nginx安装文档
  10. 51 nod 1456 小K的技术(强连通 + 并查集)
  11. 使用redis构建文章投票系统
  12. VS + QT 出现 LNK2001 无法解析的外部符号 QMetaObject 的问题
  13. WebBrowser控件的NavigateToString()方法 参数 为中文时乱码问题的解决。
  14. 【树形期望DP】BZOJ3566- [SHOI2014]概率充电器
  15. const constptr 和引用的盲点(未解决)
  16. 【LeetCode】跳跃游戏
  17. iOS开发-UITextView实现PlaceHolder的方式
  18. AsmTools
  19. django模板中自动加载static
  20. JAVA 从头开始&lt;四&gt;

热门文章

  1. JS——思维拓展
  2. Android本地消息推送
  3. comdlg32.dll
  4. CSS 之自定义滚动条样式
  5. select2下拉插件
  6. 简述cookie ,localStrage,sessionStorage的区别?
  7. (C/C++学习)13.C语言字符串处理函数(一)
  8. 思维风暴 codeforces (1060A) Phone Numbers
  9. Django - 日志工作中常用配置
  10. Boa服务器编译移植