题目描述

Farmer John has an old-time thresher (wheat harvester) that requires belts to be installed on various gears to turn the parts. The engine drives pulley 1 in a clockwise direction which attaches via a belt to pulley 2. Pulley 2 attaches via a belt to pulley 3 and so on through a total of N (2 <= N <= 1,000) pulleys (and N-1 belts).

The diagram above depicts the two ways a belt can be installed between two gears. In this illustration, pulley 1's belt directly drives pulley 2 (a 'straight' connection) and thus they will rotate in the same direction. Pulley 3 drives pulley 4 via a 'crossed belt' that reverses the direction of the rotation.

Given a list of the belt types that connect the pulleys along with the fact that pulley 1 is driven in a clockwise direction by the engine, determine the drive direction of pulley N. Each belt is described by three integers:

* S_i -- the driving (source) pulley
* D_i -- the driven (destination) pulley
* C_i -- the connection type (0=straight, 1=crossed)
Unfortunately, FJ lists the belts in random order.
By way of example, consider the illustration below. N = 4, and pulley 1 is driven clockwise by the thresher engine. Straight
belts drive pulley 2 and then pulley 3, so they rotate clockwise. The crosswise belt reverses the rotation direction so pulley 4 (pulley N) rotates counterclockwise.

POINTS: 70 约翰有一个过时的收割机,需要在它的各种滑轮上装配皮带才能让收割机的各个部分运作起 来.引擎能够驱动滑轮1向顺时针方向转动,滑轮1通过一条皮带又连接到滑轮2.滑轮2又通过一 条皮带连接到滑轮3,等等,总共有N(2 <= N <= 1000)个滑轮和N - 1条皮带.

皮带连接两个滑轮有两种方式:直接连接和交叉连接.直接连接的两个滑轮旋转方向相同, 即同为顺时针或同为逆时针.交叉连接的两个滑轮旋转方向相反.

现在给出一个列表,里面列出所有皮带的连接方式.已经知道滑轮1被引擎驱动着向顺时针方 向转动.每一条皮带由下面三个数定义:

•驱动滑轮S,输入驱动力的滑轮.

•被驱动滑轮D;,被驱使转动的滑轮.

•连接类型C,0表示直接连接,1表示交叉连接.

不幸的是,约翰的这个列表中,皮带的顺序是混乱的.所以请你写一个程序来求出滑轮N的 转动方向.

输入输出格式

输入格式:

  • Line 1: A single integer: N

  • Lines 2..N: Each line describes a belt with three integers: S_i, D_i, and C_i

输出格式:

  • Line 1: A single integer that is the rotation direction for pulley N (0=clockwise, 1=counterclockwise)

输入输出样例

输入样例#1: 复制

4
2 3 0
3 4 1
1 2 0
输出样例#1: 复制

1

说明

As in the example illustration.

思路:搜索。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 1010
using namespace std;
int n,tot;
int vis[MAXN];
int to[MAXN],head[MAXN],net[MAXN],cap[MAXN];
void add(int u,int v,int w){
to[++tot]=v;cap[tot]=w;net[tot]=head[u];head[u]=tot;
}
void dfs(int now,int fa){
for(int i=head[now];i;i=net[i])
if(to[i]!=fa){
if(cap[i]==) vis[to[i]]=vis[now];
else vis[to[i]]=!vis[now];
dfs(to[i],now);
}
}
int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
}
vis[]=;
dfs(,);
cout<<vis[n];
}

洛谷 P2913 [USACO08OCT]车轮旋转Wheel Rotation的更多相关文章

  1. bzoj1603 / P2913 [USACO08OCT]车轮旋转Wheel Rotation

    P2913 [USACO08OCT]车轮旋转Wheel Rotation 稳妥起见(防止数据出锅),用了bfs 每次的转移可以直接用异或和解决. #include<iostream> #i ...

  2. P2913 [USACO08OCT]车轮旋转Wheel Rotation

    传送门 初始状态是 0,如果有 1 的连接,0 就变 1,如果还有 1 的连接,1 就变 0,如果是 0 的连接就不变 所以就是把答案异或上所有连接,不用考虑顺序,反正最终是一样的 #include& ...

  3. 【题解】洛谷P2914[USACO08OCT]断电Power Failure

    洛谷P2914:https://www.luogu.org/problemnew/show/P2914 哇 这题目在暑假培训的时候考到 当时用Floyed会T掉 看楼下都是用Dijkstra 难道没有 ...

  4. 洛谷P1550 [USACO08OCT]打井Watering Hole

    P1550 [USACO08OCT]打井Watering Hole 题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to ...

  5. 洛谷P2911 [USACO08OCT]牛骨头Bovine Bones【水题】

    题目大意:输入S1,S2,S3,随机生成三个数x,y,z,求x+y+z出现次数最多的数(如果有多个答案输出最小的),其中1<=x<=S1,1<=y<=S2,1<=z< ...

  6. 洛谷P2912 [USACO08OCT]牧场散步Pasture Walking [2017年7月计划 树上问题 01]

    P2912 [USACO08OCT]牧场散步Pasture Walking 题目描述 The N cows (2 <= N <= 1,000) conveniently numbered ...

  7. 题解——洛谷P1550 [USACO08OCT]打井Watering Hole(最小生成树,建图)

    题面 题目背景 John的农场缺水了!!! 题目描述 Farmer John has decided to bring water to his N (1 <= N <= 300) pas ...

  8. 洛谷——P2912 [USACO08OCT]牧场散步Pasture Walking(lca)

    题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures ...

  9. 洛谷 P2912 [USACO08OCT]牧场散步Pasture Walking

    题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures ...

随机推荐

  1. TCO14 1B L3: EagleInZoo, dp,tree

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=13117&rd=15950 看到树,又是与节点有关,通常是d ...

  2. 86.express里面的app.configure作用

    以下摘自 express 3.0 的 文档 app.configure([env], callback) Conditionally invoke callback when env matches ...

  3. es6 --- 功能

    标记的模板文字 1.模板文字!确实很棒.我们不再会这样做…. const concatenatedString = "I am the " + number + "per ...

  4. Lamp安装 php-v5.6【ZendGuardLoader】的问题

    Lamp安装 php-v5.6[ZendGuardLoader]的问题 标签(空格分隔):php,linux Apache日志: 就这个问题导致无法解析运行php文件.下面是网上找的解决方案 Zend ...

  5. [ xml ] [ log4j2 ] No grammar constraints (DTD or XML Schema) referenced in the document.

    <!DOCTYPE xml> http://rx1226.pixnet.net/blog/post/321584550

  6. 记intel杯比赛中各种bug与debug【其二】:intel caffe的使用和大坑

    放弃使用pytorch,学习caffe 本文仅记录个人观点,不免存在许多错误 Caffe 学习 caffe模型生成需要如下步骤 编写network.prototxt 编写solver.prototxt ...

  7. 使用U盘作为启动盘安装ubuntu系统

     一.使用U盘刻录镜像 1.安装之后我们打开软件,点击文件打开,找到我们刚才进行下载的Ubuntu的ISO文件,然后点击打开,完成ISO文件的加载.接着我们插入U盘,点击UltraISO启动选项,然后 ...

  8. token登录验证机制

    一张图解释 token登录验证机制

  9. EF框架—Database-First

    ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案,现已经包含在 Visual Studio 2008 S ...

  10. Mysql忘记rootpassword

    1,停止MYSQL服务,CMD打开DOS窗体.输入 net stop mysql 2,在CMD命令行窗体,进入MYSQL安装文件夹 比方E:\Program Files\MySQL\MySQL Ser ...