随便模拟下就过了qwq

然后忘了特判WA了QwQ

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <queue>
using namespace std;
int n,u[],v[],fir[],nxt[],cnt=,dep[],squ[];
set<int> sons[];
void addedge(int ui,int vi){
cnt++;
u[cnt]=ui;
v[cnt]=vi;
nxt[cnt]=fir[ui];
fir[ui]=cnt;
}
void dfs(int u,int f){
for(int i=fir[u];i;i=nxt[i]){
if(v[i]==f)
continue;
dep[v[i]]=dep[u]+;
sons[u].insert(v[i]);
dfs(v[i],u);
}
}
int main(){
scanf("%d",&n);
for(int i=;i<=n-;i++){
int a,b;
scanf("%d %d",&a,&b);
addedge(a,b);
addedge(b,a);
}
queue<int> q;
for(int i=;i<=n;i++)
scanf("%d",&squ[i]);
dep[]=;
dfs(,);
q.push(squ[]);
for(int i=;i<=n;){
if (q.empty()&&i==n) {
break;
}
else if(q.empty()&&i!=n){
printf("No\n");
return ;
}
int x=q.front();
q.pop();
for(int j=;j<=sons[x].size();j++){
if(sons[x].count(squ[i+j])){
q.push(squ[i+j]);
continue;
}
else{
printf("No\n");
return ;
}
}
i+=sons[x].size();
}
printf("Yes\n");
return ;
}

题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T4(模拟)的更多相关文章

  1. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)

    还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...

  2. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)

    是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...

  3. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T2(模拟)

    题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstr ...

  4. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T1(找规律)

    就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #inclu ...

  5. 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Swap操作显然只能对(i-1,i)执行才有用. 不然直接将i翻转以及j翻转 显然比直接交换更优. 那么现在我们就相当于有两种操作. ...

  6. 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) B】Reach Median

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 将数组排序一下. 考虑中位数a[mid] 如果a[mid]==s直接输出0 如果a[mid]<s,那么我们把a[mid]改成s ...

  7. 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) A】Packets

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 多重背包的二进制优化. 就是将数量x分成接近log2x份 然后这log2x份能组合成1..x内的所有数字. 从而将多重背包转化成01 ...

  8. Manthan, Codefest 18 (rated, Div. 1 + Div. 2) F 单调栈 + 贡献 + 计数

    https://codeforces.com/contest/1037/problem/F 题意 function z(array a, integer k): if length(a) < k ...

  9. Manthan, Codefest 18 (rated, Div. 1 + Div. 2) E bfs + 离线处理

    https://codeforces.com/contest/1037/problem/E 题意 有n个人,m天,在第i天早上,x和y会成为朋友,每天晚上大家都要上车,假如一个人要上车那么他得有至少k ...

随机推荐

  1. Python datetime获取详细时间

    说明:datetime是date和time的结合体,包含了date和time的所有信息 datetime常见用法: 1.datetime.datetime.now()返回一个UTC时间的datetim ...

  2. 20155228 实验三 敏捷开发与XP实践

    20155228 实验三 敏捷开发与XP实践 实验内容 1. XP基础 2. XP核心实践 3. 相关工具 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)>& ...

  3. 【Linux学习九】负载均衡

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 一.高并发 随着应用访问量的增加,带来高并发处理问题. 具体有两个: ...

  4. MySql获取两个日期间的时间差

    [1]MySql 语言获取两个日期间的时间差 DATEDIFF 函数可以获得两个日期之间的时间差.但是,这个函数得出的结果是天数. 需要直接获取秒数可使用TIMESTAMPDIFF函数.应用示例如下: ...

  5. 为什么C++函数形参默认值从最末一个赋值?

    [1]函数调用时形参的压栈顺序 1.示例代码如下(VS2010): #include <iostream> using namespace std; ); void fun(int a, ...

  6. File §1

    The Class of File, it can be seen as one document, also can be seen as list of documents. File  f = ...

  7. 【转】SQLyog SSH 密钥登陆认证提示: No supported authentication methods available 解决方法

    问题背景: 问题原因: SQLyog不支持非标准的的私钥格式 解决方案: 使用puttyGen重新导入原来的私钥,然后重新保存成PPK证书文件,最后用SQLyog加载该PPK文件即可. 效果截图: 原 ...

  8. foreach 语句

    foreach  语句很适合用来枚举   如数组.列表.集合之类的数据结构中的元素.  不必准确知道元素个数.如果基数据不包含任何元素,则foreach循环不执行 foreach(<元素> ...

  9. 第二节 JavaScript基础

    JavaScript组成及其兼容性: ECMAScript:解释器,翻译,用于实现机器语言和高级语言的翻译器:几乎没有兼容性问题 DOM(Document Object Model):文档对象模型,文 ...

  10. Kattis之旅——Perfect Pth Powers

    We say that x is a perfect square if, for some integer b, x = b2. Similarly, x is a perfect cube if, ...