【CS Round #44 (Div. 2 only) C】Check DFS
【链接】点击打开链接
【题意】
【题解】
【错的次数】
3
【反思】
【代码】
/* */
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long double typedef pair<int, int> pii;
typedef pair<LL, LL> pll; //mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e5; int n, m, p[N + 10], cnt = 2;
vector <int> g[N + 10];
bool bo[N + 10]; void dfs(int x) {
if (cnt > n) {
puts("1");
exit(0);
}
bo[x] = true;
int len = sz(g[x]), c = 0, fi = 0;
rep1(i, 0, len - 1) {
int y = g[x][i];
if (!bo[y]) {
c++;
if (y == p[cnt]) fi = 1;
}
}
if (fi) {
dfs(p[cnt++]);
if (c > 1) dfs(x);
}
else {
if (c > 0) {
puts("0");
exit(0);
}
}
} int main() {
//Open();
//Close();
ri(n), ri(m);
rep1(i, 1, n) ri(p[i]);
rep1(i, 1, m) {
int x, y;
ri(x), ri(y);
g[x].pb(y), g[y].pb(x);
}
dfs(1);
puts("0");
return 0;
}
【CS Round #44 (Div. 2 only) C】Check DFS的更多相关文章
- 【CS Round #44 (Div. 2 only) D】Count Squares
		
[链接]点击打开链接 [题意] 给你一个0..n和0..m的区域. 你可以选定其中的4个点,然后组成一个正方形. 问你可以圈出多少个正方形. (正方形的边不一定和坐标轴平行) [题解] 首先,考虑只和 ...
 - 【CS Round #44 (Div. 2 only) A】Frequent Numbers
		
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 大水题 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #include &l ...
 - 【CS Round #44 (Div. 2 only) B】Square Cover
		
[链接]点击打开链接 [题意] 给你一个n*m的矩形,让你在其中圈出若干个子正方形,使得这些子正方形里面的所有数字都是一样的. 且一样的数字,都是在同一个正方形里面.问你有没有方案. [题解] 相同的 ...
 - 【CS Round #46 (Div. 1.5) E】Ultimate Orbs
		
[链接]链接 [题意] n个人从左到右站在一条直线上.每个人都有一个能力值g[i],然后每个人可以将相邻的一个人打败. 然后它的能力值能够增加相应的能力值(就是打败了的那个人的能力值). A能够打败B ...
 - 【CS Round #36 (Div. 2 only) A】Bicycle Rental
		
[题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...
 - 【CS Round #37 (Div. 2 only) D】Reconstruct Graph
		
[Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...
 - 【CS Round #37 (Div. 2 only) B】Group Split
		
[Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...
 - 【CS Round #37 (Div. 2 only) A】Boring Number
		
[Link]:https://csacademy.com/contest/round-37/task/boring-number/ [Description] 让你找离平均数最近的一个数的下标; [S ...
 - 【CS Round #39 (Div. 2 only) D】Seven-segment Display
		
[Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...
 
随机推荐
- SpringBoot学习笔记(八):SpringBoot启动端口+访问路、SpringBoot配置文件yml、SpringBoot多环境区分、SpringBoot打包发布
			
SpringBoot启动端口+访问路径 配置文件: server.port=9090 server.context-path=/springboot 现在只能用http://127.0.0.1:909 ...
 - 群晖系统下btfs(占用5%)和ext4文件格式的硬盘占用和选择
			
1个人感觉选择ext4就可以,毕竟重要数据会设置raid1 不重要的数据也不需要快照什么的 商用除外 对于一个4t的硬盘 实际容量3726G 使用ext4可用空间3666G,群晖 占用60G大概1.6 ...
 - C开发系列-预处理指令
			
简介 OC程序执行过程,在源代码编译成0跟1的二进制文件之前.执行的指令称之为预处理指令. 所有的预处理指令都是以#开头.#import也是预处理指令.预处理指令主要分为三种 宏定义 条件编译 文件包 ...
 - Linux实现自动登录
			
使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明,初学者一般都是照抄.收藏.可是为什么要这么写却不知其然.本文用一个最短的例子说明脚本的原理. 脚本代码如下: #!/usr/b ...
 - Java校验时间段重叠
			
1.需求 要求保存每一条数据的startTime.endTime的中间时间段是唯一的,跟其他数据时间段不能存在冲突 比如: (2019-03-01 -> 2019-03-03 ) (2019- ...
 - MySQL8.0.17 - 初探 Clone Plugin
			
MySQL8.0.17推出了一个重量级的功能:clone plugin.允许用户可以将当前实例进行本地或者远程的clone.这在某些场景尤其想快速搭建复制备份或者在group replication里 ...
 - [转]模块化——Common规范及Node模块实现
			
Node在实现中并非完全按照CommonJS规范实现,而是对模块规范进行了一定的取舍,同时也增加了少许自身需要的特性.本文将详细介绍NodeJS的模块实现 引入 nodejs是区别于javascrip ...
 - 166 链表倒数第n个结点
			
原题网址:https://www.lintcode.com/problem/nth-to-last-node-in-list/description 描述 找到单链表倒数第n个节点,保证链表中节点的最 ...
 - sql删除重复的记录保留一条
			
delete from A_TO_NOW where yuan_name in (select yuan_name from A_TO_NOW group by yuan_name hav ...
 - 解决CSocket高数据传输问题
			
这个是自己项目中发现的问题,所以这个不一定适用于你的. 仅供参考. 头文件: ESSocket.h // ESSocket.h : header file // #ifndef ESSOCKET_H ...