题意:

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. LT1072 -- Wide-range voltage regulator automatically selects operating mode

    The circuit in Figure 1 delivers programming voltages to an EEPROM under the control of an external ...

  2. 创建Windows窗体 : WinMain() 与 WndProc()

    #include <windows.h> #include <mmsystem.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, ...

  3. mysqlslap

    常用参数[options]详细介绍: --concurrency代表并发数量,多个可以用逗号隔开.例如:--concurrency=50,200,500 --engines代表要测试的引擎,可以有多个 ...

  4. appium+python自动化24-滑动方法封装(swipe)

    swipe介绍 1.查看源码语法,起点和终点四个坐标参数,duration是滑动屏幕持续的时间,时间越短速度越快.默认为None可不填,一般设置500-1000毫秒比较合适. swipe(self, ...

  5. 安卓源码下载 windows

    git clone https://android.googlesource.com/name Name Descriptionaccessories/manifest device/asus/deb ...

  6. iOS: 详细的正则表达式

    一.简单的正则规则 1.由数字.26个英文字母或者下划线组成的字符串: ^[-9a-zA-Z_]{,}$ 2.非负整数(正整数 + 0 ): ^/d+$ 3. 正整数: ^[-]*[-][-]*$ 4 ...

  7. T-SQL经典语句(SQL server)

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  8. 如何更改postgresql的最大连接数

    改文件 postgresql.conf 里的 #max_connections=32 为 max_connections=1024 以及另外相应修改 share_buffer 参数.

  9. c++学习之多态(虚函数和纯虚函数)

    c++是面向对象语言,面向对象有个重要特点,就是继承和多态.继承之前学过了,就是一种重用类的设计方式.原有的类叫父类,或者基类,继承父类的类叫子类.在设计模式中,我们总是要避免继承,推荐用组合.因为继 ...

  10. ItermCF的MR并行实现

    ItermCF的MR并行实现 @(Hadoop) ItermCF的基本思想 基于物品相似度的协同过滤推荐的思想大致可分为两部分: 1.计算物与物之前的相似度 2.根据用户的行为历史,给出和历史列表中的 ...