随便模拟下就过了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. Vue系列之 => 组件切换

    组件切换方式一 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  2. 20155228 2017-5-10 课堂测试:Arrays和String单元测试

    20155228 2017-5-10 课堂测试:Arrays和String单元测试 题目和要求 在IDEA中以TDD的方式对String类和Arrays类进行学习 测试相关方法的正常,错误和边界情况 ...

  3. IO多路复用 IO异步

    一.概念说明 同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的环境给出的答案是不同的.所以先限定一下本文的环境.本文讨论的背景是Linux环境下的network I ...

  4. Runtime单例模式类 -- 控制电脑关机

    package demo1; import java.io.IOException; public class RunTimeDemo { public static void main(String ...

  5. 那个写书教你交易期权的人James Cordier爆仓了

    那个写书教你交易期权的人James Cordier爆仓了 11月15日,James Cordier掌管的期权交易公司OptionSellers.com通过邮件告知投资者,其公司管理的账户遭遇了毁灭性的 ...

  6. rabbitMq 教程

    https://github.com/401Studio/WeekLearn/issues/2 目录 RabbitMQ 概念 exchange交换机机制 什么是交换机 binding? Direct ...

  7. Mybatis+MySQL动态分页查询

    https://blog.csdn.net/qq_34137397/article/details/63289621 mybatis有两种分页方法 1.内存分页,也就是假分页.本质是查出所有的数据然后 ...

  8. JustOj 2043: N!

    题目描述 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出,赛后我们会检查代码,如有发现,该位同学总分记0分处理) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把 ...

  9. [转载]window.location.href的用法(动态输出跳转)

    无论在静态页面还是动态输出页面中window.location.href都是不错的用了跳转的实现方案   javascript中的location.href有很多种用法,主要如下. self.loca ...

  10. kivy中文

    from kivy.config import Config Config.set('kivy', 'default_font', [ 'msgothic', 'DroidSansFallback.t ...