2017 Mid Central Regional G. Faulty Robot(dfs + 尬模)
这道题看上去太像tarjan缩点了,我一上去本来想把所有的环给缩掉然后统计答案,后来发现哦,这道题不是这么回事儿。
给出黑边红边,一次性走至多只能走一次黑边,问有多少个点可以走到,并且让机器人停下来,就一次这也不是很难么,但是如果k >= 2就很难说了
爆搜就完事儿了,遇到黑边改一次再走,如果一个点走不通了就统计一下,记得入点要特判
#include <bits/stdc++.h>
using namespace std;
#define limit (20000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
ll sign = 1, x = 0;char s = getchar();
while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
return x * sign;
}//快读
void write(ll x){
if(x < 0) putchar('-'),x = -x;
if(x / 10) write(x / 10);
putchar(x % 10 + '0');
}
int n;
int head[limit],cnt;
struct node{
int to,next;
bool forced;
}edge[limit];
void init(){
memset(head, -1, sizeof(head));
cnt = 0;
}
int ans;
void add(int x, int y,bool flag = false){
edge[cnt].to = y;
edge[cnt].next = head[x];
edge[cnt].forced = flag;
head[x] = cnt++;
}
int vis[limit],tot[limit];
void dfs(int u, int flag){
bool ok = false;
traverse(u){
int v = edge[i].to;
bool status = edge[i].forced;
if(status){
if(!vis[v]){
vis[v] = 1;
dfs(v,flag);
vis[v] = 0;
}
ok = true;
}else if(flag){
if(!vis[v]){
vis[v] = 1;
dfs(v,!flag);
vis[v] = 1;
}
}
}
if(!ok)tot[u]= 1;
}
int main() {
#ifdef LOCAL
FOPEN;
#endif
n = read();
int m = read();
init();
rep(i ,1,m){
int x = read(), y =read();
if(x < 0){
add(-x,y, true);
}else{
add(x,y);
}
}
int ok = 1;
traverse(1)if(edge[i].forced){
ok = 0;
break;
}
tot[1] = ok;
//vis[1] = 1;;
ans = 0;
dfs(1,true);
rep(i,1,n){
ans += tot[i];
}
write(ans);
return 0;
}
2017 Mid Central Regional G. Faulty Robot(dfs + 尬模)的更多相关文章
- 2017 Mid Central Regional G.Hopscotch (组合计数)
这道题有点意思,给出点(N,N),你在原点处向目标点走,每次只能向x和y两个方向走路,每次xy两个方向的步幅分别不能小于dx和dy,问走到终点的方案数,答案对1e9 + 7取模 这道题最直接的想法就是 ...
- 2017 Mid Central Regional F.Orderly Class(大水题)
这两天刷了两道过去的原题,看看思维还是8太行. 这道题问给出两个字符串,要求只翻转一次,问有几种不同的方法使得a串变成b串 我一开始没看到只翻转一次,还以为是个计数 + 字符串dp大难题,心想当年的学 ...
- HDU 6270 Marriage (2017 CCPC 杭州赛区 G题,生成函数 + 容斥 + 分治NTT)
题目链接 2017 CCPC Hangzhou Problem G 题意描述很清晰. 考虑每个家庭有且仅有$k$对近亲的方案数: $C(a, k) * C(b, k) * k!$ 那么如果在第$1$ ...
- 2012 East Central Regional Contest 解题报告
昨晚各种莫名其妙卡题. 不过细看这套题还挺简单的.全是各种暴力. 除了最后一道题计算几何看起来很麻烦的样子,其他题都是很好写的吧. A. Babs' Box Boutique 题目大意是给出不超过10 ...
- 2017, X Samara Regional Intercollegiate Programming Contest 题解
[题目链接] A - Streets of Working Lanterns - 2 首先将每一个括号匹配串进行一次缩减,即串内能匹配掉的就匹配掉,每个串会变成连续的$y$个右括号+连续$z$个左括号 ...
- G - Oil Deposits(dfs)
G - Oil Deposits Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 2015南阳CCPC G - Ancient Go dfs
G - Ancient Go Description Yu Zhou likes to play Go with Su Lu. From the historical research, we fou ...
- CodeForces 589J Cleaner Robot (DFS,或BFS)
题意:给定n*m的矩阵,一个机器人从一个位置,开始走,如果碰到*或者边界,就顺时针旋转,接着走,问你最后机器人最多能走过多少格子. 析:这个题主要是题意读的不大好,WA了好几次,首先是在*或者边界才能 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map
A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- 浅谈OpenGL之DSA
今天准备写一篇文章简单介绍一下OpenGL4.5引入的一个新的扩展ARB_direct_state_access,这个扩展为OpenGL引入了一个新的特性就是Direct State Acess,下文 ...
- [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT)
[Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i ...
- Elasticsearch原理解析与性能调优
基本概念 定义 一个分布式的实时文档存储,每个字段 可以被索引与搜索 一个分布式实时分析搜索引擎 能胜任上百个服务节点的扩展,并支持 PB 级别的结构化或者非结构化数据 用途 全文检索 结构化搜索 分 ...
- 【Kata Daily 190909】The Supermarket Queue(超市队列)
题目: There is a queue for the self-checkout tills at the supermarket. Your task is write a function t ...
- python_socket登陆验证_明文
client.py import socket import struct sk=socket.socket() sk.connect(('127.0.0.1',9005)) while True: ...
- CVE-2020-0769逆向分析
受影响版本: 系统 版本 Microsoft Windows 10 Windows 10 1607 Windows 10 1709 Windows 10 1803 Windows 10 1809 Wi ...
- 【linux】gpio子系统
目录 前言 linux子系统 gpio子系统 gpio子系统实战-系统调用 前言 目前不涉及驱动源码 参考链接 linux子系统 在 Linux 系统中 绝大多数硬件设备都有非常成熟的驱动框架 驱动工 ...
- Linux程序开发中如何判断目录是否为根目录?
问题引入 判断某个目录字符串是否是根目录,咋一听很简单,只要判断字符串是否是"/"即可,但是,很多情况下使用的路径是相对路径,那么如何判断相对路径是根目录呢? 思路分析 熟悉Lin ...
- js常用通用函数
//判断是否数字 function isNumber(str){ var n = Number(str); if (!isNaN(n)){ return true; }else{ return fal ...
- Springboot 完整搭建快速入门,必看!
前言 手把手教你Springboot微服务项目搭建快速入门,通过本文学习Springboot的搭建快速入门,掌握微服务大致的配置服务,后续将会继续将核心组件引入到项目中,欢迎关注,点赞,转发. Spr ...