【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 ...
随机推荐
- RPM软件包管理的查询功能
以后大家升级rpm包的时候,不要用Uvh了! 我推荐用Fvh 前者会把没有安装过得包也给装上,后者只会更新已经安装的包 总结:未安装的加上小写p,已安装的不需要加p 查询q rpm {- ...
- WebSite和WebApplication的区别
1. WebApplication(Web应用程序)和WebSite(网站)的区别:WebSite是为了兼容从ASP转过来的开发人员的习惯而存在的,用起来简单,例如:不需要创建命名控件.C#代码修改以 ...
- 【转】 JSONObject使用方法
随笔- 46 文章- 0 评论- 132 JSONObject简介 本节摘要:之前对JSON做了一次简单的介 绍,并把JSON和XML做了一个简单的比较:那么,我就在想,如果是一个json格式的字 ...
- 【转】php json_encode中文为空的解决办法
转自:http://www.cnblogs.com/oldphper/p/4123415.html 本文列举3个方法,实现json_encode()后的string显示中文问题. 做接口时不需要,但存 ...
- iOS7 中的JavaScriptCore简单介绍
以前写过一篇介绍如何使用第三方库在ios上进行js和oc交互调用的文章,链接如下 iOS 使用UIWebView把oc代码和javascript相关联.当时建立项目时,仍然是ios6时代,所以没有原生 ...
- iOS 中的Certificate,Provisioning Profile 等在code singing中用到的信息
注册apple id 有1年多了,这些概念还是模模糊糊的,决定在这里总结一下. 请参阅官方文档 App Distribution Guide code singing的作用如下: Code signi ...
- Java for LeetCode 160 Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- SpringJDBC的简单应用
此处写上应用JdbcTemplate的dao操作数据库的一些代码(含基本的增删改查,注:重点是查询出多条语句的写法): package org.sakaiproject.zhaorui.dao.imp ...
- Android之UI控件
本文主要包括以下内容 Spinner的使用 Gallery的使用 Spinner的使用 Spinner的实现过程是 1. 在xml文件中定义Spinner的控件 2. 在activity中获取Spin ...
- 字符串匹配与KMP算法实现
>>字符串匹配问题 字符串匹配问题即在匹配串中寻找模式串是否出现, 首先想到的是使用暴力破解,也就是Brute Force(BF或蛮力搜索) 算法,将匹配串和模式串左对齐,然后从左向右一个 ...