【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1603
这种水题。。。
dfs没话说。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1005;
int ihead[N], inext[N], to[N], cnt, d[N], f[N], n, vis[N];
void dfs(const int &x, const int &t) {
if(vis[x]) return;
vis[x]=1;
f[x]=t;
for(int i=ihead[x]; i; i=inext[i]) dfs(to[i], t^d[i]);
} int main() {
read(n);
int u, v, w;
rep(i, n-1) {
read(u); read(v); read(w);
inext[++cnt]=ihead[u]; ihead[u]=cnt; to[cnt]=v; d[cnt]=w;
}
dfs(1, 0);
print(f[n]);
return 0;
}
Description
Input
Output
Sample Input
2 3 0
3 4 1
1 2 0
Sample Output
HINT
Source
【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)的更多相关文章
- BZOJ 1603: [Usaco2008 Oct]打谷机
		题目 1603: [Usaco2008 Oct]打谷机 Time Limit: 5 Sec Memory Limit: 64 MB Description Farmer John有一个过时的打谷机( ... 
- BZOJ 1603 [Usaco2008 Oct]打谷机 dfs
		题意:id=1603">链接 方法:暴力 解析: 搜1到n路径上的边权异或和-. 这几个水题刷的我有点-.. 代码: #include <cstdio> #include ... 
- bzoj 1603: [Usaco2008 Oct]打谷机【瞎搞】
		一棵树,碰到改变转向的边就异或一下,从1dfs一遍 #include<iostream> #include<cstdio> using namespace std; const ... 
- bzoj1603: [Usaco2008 Oct]打谷机 (纱布题)
		Description Input Output Sample Input Sample Output Time Limit: 5 Sec Memory Limit: 64 MB Submit: 7 ... 
- BZOJ1603: [Usaco2008 Oct]打谷机
		1603: [Usaco2008 Oct]打谷机 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 602 Solved: 458[Submit][Stat ... 
- BZOJ 1602: [Usaco2008 Oct]牧场行走 倍增裸题
		Description N头牛(2<=n<=1000)别人被标记为1到n,在同样被标记1到n的n块土地上吃草,第i头牛在第i块牧场吃草. 这n块土地被n-1条边连接. 奶牛可以在边上行走, ... 
- BZOJ 1603 USACO 2008 Oct. 打谷机
		[题解] 水题.. 保存连接方式,按顺序处理即可. #include<cstdio> #include<algorithm> using namespace std; int ... 
- BZOJ 1601 [Usaco2008 Oct]灌水
		1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec Memory Limit: 162 MB Description Farmer John已经决定把水灌到他的n(1 ... 
- bzoj 1602 [Usaco2008 Oct]牧场行走(LCA模板)
		1602: [Usaco2008 Oct]牧场行走 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 379 Solved: 216[Submit][Sta ... 
随机推荐
- C/C++ 文件操作
			C/C++ 文件操作大概有以下几种 1.C的文件操作: 2.C++的文件操作: 3.WINAPI的文件操作: 4.BCB库的文件操作: 5.特殊文件的操作. 当然了,水题时最常用的当然还是: freo ... 
- 二模 06day2
			很长时间没更新有意义的题目了呢,这是一套题撒,于是乎我便开心的边刷题边发题解了撒. 第一题: interval 比较好玩的一题撒, 分分钟过了, 就是模拟贪吃蛇但是没有食物(嗯,只要你判断冲突). 整 ... 
- Windows下的git配置
			需要的配置: 1.C:\Program Files\Git\etc\git-completion.bash: alias ls='ls --show-control-chars --color=aut ... 
- Ubuntu 更改文件夹权限及chmod详细用法
			转自: http://blog.chinaunix.net/uid-21880738-id-1813031.html 对Document/目录下的所有子文件与子目录执行相同的权限变更: Documen ... 
- 【Hibernate】Hibernate系列5之检索策略
			检索策略 5.1.类级别检索策略 5.2.set多对多.一对多检索策略 5.3.多对一.一对一检索策略 HQL作用: http://zhidao.baidu.com/link?url=dnAdJWR7 ... 
- Reverse Pairs
			For an array A, if i < j, and A [i] > A [j], called (A [i], A [j]) is a reverse pair.return to ... 
- 57. 数对之差的最大值:4种方法详解与总结[maximum difference of array]
			[本文链接] http://www.cnblogs.com/hellogiser/p/maximum-difference-of-array.html [题目] 在数组中,数字减去它右边的数字得到一个 ... 
- NSUrlConnection 和 NSUrlRequest 的关系
			开始看到这2个名字,总感觉NSUrlConnection才是主要的网络请求类,其实不是,先看官方文档 An NSURLConnection object lets you load the conte ... 
- iOS 基于UIWebView的应用特点
			现在有许多ios应用都是基于UIWebView的应用,比如phonegap做出的那些程序.最近我也接触到了一个类似的程序,今天在这里分享一下这类程序的特点. 用UIWebView来实现程序,自然少不了 ... 
- 用RPM包安装MySQL的默认安装路径问题
			在安装PHP时候要对一些配置选项进行设置,其中就有:--with-mysql[=DIR]:包含MySQL扩展,[=DIR]指定mysql安装目录,省略[=DIR]则为默认位置/usr--with-my ... 
