题意:

id=1603">链接

方法:暴力

解析:

搜1到n路径上的边权异或和….

这几个水题刷的我有点…..

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1010
using namespace std;
int n,cnt;
struct node
{
int from,to,val,next;
}edge[N<<1];
int head[N];
void init()
{
memset(head,-1,sizeof(head));
cnt=1;
}
void edgeadd(int from,int to,int val)
{
edge[cnt].from=from,edge[cnt].to=to,edge[cnt].val=val;
edge[cnt].next=head[from];
head[from]=cnt++;
}
void dfs(int now,int fa,int worth)
{
if(now==n)
{
printf("%d\n",worth);
exit(0);
}
for(int i=head[now];i!=-1;i=edge[i].next)
{
int to=edge[i].to;
if(to==fa)continue;
dfs(to,now,worth^edge[i].val);
}
}
int main()
{
init();
scanf("%d",&n);
for(int i=1;i<n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
edgeadd(x,y,z),edgeadd(y,x,z);
}
dfs(1,0,0);
}

BZOJ 1603 [Usaco2008 Oct]打谷机 dfs的更多相关文章

  1. BZOJ 1603: [Usaco2008 Oct]打谷机

    题目 1603: [Usaco2008 Oct]打谷机 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John有一个过时的打谷机( ...

  2. bzoj 1603: [Usaco2008 Oct]打谷机【瞎搞】

    一棵树,碰到改变转向的边就异或一下,从1dfs一遍 #include<iostream> #include<cstdio> using namespace std; const ...

  3. 【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1603 这种水题... dfs没话说.. #include <cstdio> #inclu ...

  4. BZOJ1603: [Usaco2008 Oct]打谷机

    1603: [Usaco2008 Oct]打谷机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 602  Solved: 458[Submit][Stat ...

  5. bzoj1603: [Usaco2008 Oct]打谷机 (纱布题)

    Description Input Output Sample Input Sample Output Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 7 ...

  6. bzoj 1602 [Usaco2008 Oct]牧场行走(LCA模板)

    1602: [Usaco2008 Oct]牧场行走 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 379  Solved: 216[Submit][Sta ...

  7. BZOJ 1602: [Usaco2008 Oct]牧场行走( 最短路 )

    一棵树..或许用LCA比较好吧...但是我懒...写了个dijkstra也过了.. ---------------------------------------------------------- ...

  8. BZOJ 1599: [Usaco2008 Oct]笨重的石子( 枚举 )

    直接枚举 ------------------------------------------------------------------------------- #include<cst ...

  9. BZOJ 1600: [Usaco2008 Oct]建造栅栏( dp )

    QAQ我没读过书...四边形都不会判定了 简单的dp.... --------------------------------------------------------------------- ...

随机推荐

  1. IDA IDC Tutorials: Additional Auto-Commenting

    https://www.hex-rays.com/products/ida/support/tutorials/idc/autocomment.shtml This program creates a ...

  2. Webstorm实时编译SASS和LESS

    Webstorm自带一个File Watchers功能,设置一下,即可实时编译SASS,LESS等 菜单:File->Settings->左栏Tools下的File Watchers,按右 ...

  3. Apache下error.log文件太大的处理

    偶尔发现Apache下的错误日志非常的大,有4G多,先停止Apache服务的所有进程,最简单就是输命令:net stop apache2.2,然后删除 Apache2/logs/目录下的 error. ...

  4. 使用 pm2-web 监控 pm2 服务运行状态

    pm2-web 是一款 pm2 服务状态监控程序,基于 web . 安装 $ npm install -g pm2-web 运行(默认是在8080端口) $ pm2-web 配置 pm2-web 将会 ...

  5. java.io.FileNotFoundException: ***(Too many open files)

    http://yizhilong28.iteye.com/blog/1154098 在linux下跑一个多线程读取文件的程序,待读取文件有数十万个.程序读取过程中抛出如下异常*****(Too man ...

  6. Android内存调试命令

    adb shell dumpsys meminfo 包名 比如: adb shell dumpsys meminfo cn.com.test

  7. Android Studio调试报错am startservice

    今天下载了一个Android studio2.3.0版本,想调试一下自己的一个项目,但是发现项目编译运行正常,但是一调试就报错: 09/14 16:19:13: Launching app$ adb ...

  8. 无法对数据库'XXX' 执行删除,因为它正用于复制"的解决方

    困扰二天的问题终于得以解决,貌似一个棘手的问题只要知道方法也似乎变得异常简单,记录此次的解决方法,避免遗忘. 无法对 数据库'UDS' 执行 删除,因为它正用于复制. (.Net SqlClient ...

  9. SQL CREATE INDEX

    n relational database, Index will be the important mechanism for boosting performance. Index is impo ...

  10. IOS UITableView删除功能

    UITbableView作为列表展示信息,除了展示的功能,有时还会用到删除,比如购物车等.删除功能可以直接使用系统自带的删除功能,当横向轻扫cell时,右侧出现红色的删除按钮,点击删除当前cell. ...