【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 ...
随机推荐
- Textview下划线注册用户跳转实现
在xml中: <TextView android:id="@+id/textView_regtext" android:layout_width="wrap_con ...
- grep与egrep
当只有一个匹配条件时:egrep pattern file等价于grep -E pattern file 例如: 当多个匹配条件时,只能用egrep -e pattern1 -e pattern2 - ...
- ubuntu14.04安装dropbox
官网地址: https://www.dropbox.com/install?os=lnx 自己的系统如果没有设置全局翻(qiang)代理,使用deb文件安装后不能直接使用,因为还需要到官网安装prop ...
- 【持续集成】使用Jenkins实现多平台并行集成
使用Jenkins实现多平台并行集成 二月 15, 2012 暂无评论 我们的后端C应用都是支持跨平台的,至少目前在Linux和Solaris上运行是没有问题的,这样一来我们在配置持续集成环境时就要考 ...
- Sharepoint 2010 创建栏 计算栏
SharePoint 创建栏时,可以添加计算字段, 网上查了查,相关资料如下: http://wenku.baidu.com/view/936239e9b8f67c1cfad6b88f.html ht ...
- css行内样式
<title>归园田居</title> </head> <body> <h2>归园田居</h2> <p>种豆南山下, ...
- 使用kettle转换中的JavaScript对密码进行加密和解密
日常开发中,为了确保账号和密码的安全,时常要对密码进行加密和解密.然而kettle是怎么对密码进行加密和解密的呢? 下面的代码需要再转换中的JavaScript中运行. var encrypted_p ...
- android.mk文件里的通配符
比方你有如下目录,要编译Classes目录和Code目录下所有cpp src |-android.mk |-Classes |-A.cpp |-B.cpp |-....cpp |-Code |-E.c ...
- c++标准库中几个常见的数据结构的区别和应用规则
转载自http://www.lifecrunch.biz/archives/202 vector和built-in数组类似,它拥有一段连续的内存空间,并且起始地址不变,因此它能非常好的支持随即存取,即 ...
- iOS 和Android中的正则表达式简单使用
ios 中需要使用NSRegularExpression类,NSTextCheckingResult类. 下面给出最基本的实现代码 NSRegularExpression *regex = [NSRe ...