题目描述

We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball.

Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box xi, then he puts it into box yi.

Find the number of boxes that may contain the red ball after all operations are performed.

Constraints
2≤N≤105
1≤M≤105
1≤xi,yi≤N
xi≠yi
Just before the i-th operation is performed, box xi contains at least 1 ball.

输入

The input is given from Standard Input in the following format:

N M
x1 y1
:
xM yM

输出

Print the number of boxes that may contain the red ball after all operations are performed.

样例输入

3 2
1 2
2 3

样例输出

2

提示

Just after the first operation, box 1 is empty, box 2 contains one red ball and one white ball, and box 3 contains one white ball.

Now, consider the second operation. If Snuke picks the red ball from box 2, the red ball will go into box 3. If he picks the white ball instead, the red ball will stay in box 2. Thus, the number of boxes that may contain the red ball after all operations, is 2.

这是我的代码。我的队友刚开始并没有先标记再遍历

#include <bits/stdc++.h>

using namespace std;
struct data
{
int sum=;
int red=;
}s[];
int main()
{
ios::sync_with_stdio(false);
int n,m,i;
cin>>n>>m;
s[].sum=s[].red=;
for(i=;i<=n;i++) s[i].sum=;
int x,y,ans=;
while(m--){
cin>>x>>y;
if(s[x].red==&&s[x].sum==){
s[y].red=;
s[x].sum=s[x].red=;
s[y].sum++;
}
else if(s[x].red==&&s[x].sum!=){
s[y].sum++;
s[x].sum--;
}
else if(s[x].red==&&s[x].sum>){
s[x].sum--;
s[y].red=;
s[y].sum++;
}
}
for(i=;i<=n;i++){
if(s[i].red==) ans++;
}
cout<<ans<<endl;
return ;
}

Box and Ball的更多相关文章

  1. box2d中的物理世界

    box2d中的物理世界,即b2World类就是一个包含了各种物体(body,物理体,或者叫刚体),固定附着物(fixture,形状与物理体的绑定物)以及各种约束体(比如关节),并使其在当中完成各种交互 ...

  2. 用HTML5+原生js实现的推箱子游戏

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. AtCoder Grand Contest 002

    AtCoder Grand Contest 002 A - Range Product 翻译 告诉你\(a,b\),求\(\prod_{i=a}^b i\)是正数还是负数还是零. 题解 什么鬼玩意. ...

  4. RE:从零开始的AGC被虐(到)生活(不能自理)

    RE:从零开始的AGC被虐(到)生活(不能自理) 「一直注视着你,似近似远,总是触碰不到.」 --来自风平浪静的明天 AtCoder Grand Contest 001 B: Mysterious L ...

  5. AtCoder AGC #2 Virtual Participation

    在知乎上听zzx大佬说AGC练智商...于是试了一下 A.Range Product 给$a$,$b$,求$\prod^{b}_{i=a}i$是正数,负数还是$0$ ...不写了 B.Box and ...

  6. Atcoder/Topcoder 口胡记录

    Atcoder/Topcoder 理论 AC Atcoder的❌游戏示范 兴致勃勃地打开一场 AGC 看 A 题,先 WA 一发,然后花了一年时间 Fix. 看 B 题,啥玩意?这能求? 睡觉觉. e ...

  7. A*G`C002

    AGC002 A Range Product 不会,弃疗了/kk https://agc002.contest.atcoder.jp/submissions/7908938 B Box and Bal ...

  8. 【AtCoder】AGC002

    AGC002 A - Range Product #include <bits/stdc++.h> #define fi first #define se second #define p ...

  9. AGC002[BCDEF]题解

    F是计数于是就做(kan ti jie)了= = B - Box and Ball 模拟一下 每个盒子开一个d表示有的球数 可能存在红球的打个标记 传递一下就行了 #include<cstdio ...

随机推荐

  1. WOJ 1543 Array

    还是聪哥给我讲的思路才知道的,起初我利用两两互质去求发现有问题,互质只是必要条件而非充分条件,后来还是用的标准思路 即其实最终只要保留最大的素数的幂即可,其他包含该素数幂但指数低的都不用了,这样就能保 ...

  2. sql注入入门--基本命令

    本文转载自http://blog.csdn.net/zgyulongfei/article/details/41017493 本文仅献给想学习渗透测试的sqlmap小白,大牛请绕过. > > ...

  3. 基于表单的web暴力破解

    暴力破解 概述 连续性尝试+字典+自动化 如果一个网站没有对登录接口实施防暴力破解的措施,或者实施了不合理的措施,则该网站存在暴力破解漏洞. 是否要求用户设置了复杂的密码 是否每次认证都是用安全的验证 ...

  4. [极客大挑战 2019]LoveSQL

    0x00 知识点 1:万能密码登陆 2:登陆后直接使用联合查询注入 0x01解题 登陆后进行简单测试发现是字符型注入 order by 测试数据库有多少字段 发现在4的时候报错,没有过滤,直接进行注入 ...

  5. [极客大挑战 2019]PHP

    0x00知识点 1:直接扫描目录得到网站源码. 2:public.protected与private在序列化时的区别 protected 声明的字段为保护字段,在所声明的类和该类的子类中可见,但在该类 ...

  6. i春秋2020新春公益赛WP

    Re Factory 主函数fork了一个子进程,父进程添加了一个信号处理器用于比对input,然后死循环挂起.子进程读入input,然后调用了关键函数. 跟进关键函数,发现是从一段内存中读取数据,然 ...

  7. goahead(web服务器)分析

    一.参考网址 1.源码的github地址 二.网页是采用文件读写方式,还是转换为数组方式? 1)其通过宏定义“WEBS_PAGE_ROM”来区分,我是在websPageReadData()(page. ...

  8. html分页自适应居中;css设置分页自适应居中

    制作网页列表的分页必不可少,显示的列表条数也不一样,让我们一起来看看如何让分页标签根据给定的分页自动居中呢. 对<ul>标签设置样式为:{ display: table margin:40 ...

  9. F5 BIG-IPLTM单臂组网的三种连接模式

  10. 三、VIP课程:并发编程专题->01-并发编程之Executor线程池详解

    01-并发编程之Executor线程池详解 线程:什么是线程&多线程 线程:线程是进程的一个实体,是 CPU 调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.线程自己基本上不拥有系 ...