题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T4(模拟)
随便模拟下就过了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(模拟)的更多相关文章
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)
还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)
是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T2(模拟)
题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstr ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T1(找规律)
就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #inclu ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Swap操作显然只能对(i-1,i)执行才有用. 不然直接将i翻转以及j翻转 显然比直接交换更优. 那么现在我们就相当于有两种操作. ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) B】Reach Median
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 将数组排序一下. 考虑中位数a[mid] 如果a[mid]==s直接输出0 如果a[mid]<s,那么我们把a[mid]改成s ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) A】Packets
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 多重背包的二进制优化. 就是将数量x分成接近log2x份 然后这log2x份能组合成1..x内的所有数字. 从而将多重背包转化成01 ...
- 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 ...
- Manthan, Codefest 18 (rated, Div. 1 + Div. 2) E bfs + 离线处理
https://codeforces.com/contest/1037/problem/E 题意 有n个人,m天,在第i天早上,x和y会成为朋友,每天晚上大家都要上车,假如一个人要上车那么他得有至少k ...
随机推荐
- Marlin 溫度感應器 數值轉換對應表
Marlin 溫度感應器 數值轉換對應表 (2014/03/27)Update: 自己實測了這個自動產生的對應表,結果測得的溫度與實際值仍有相當大的誤差.看來還是要回頭用測量的方式來校正溫度... ...
- Linux基础命令---文本编辑ex
ex ex会启动vim编辑器,它的执行效果和vim –E相同.从ex模式回到普通模式,可以在vim中输入:vim. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.op ...
- cookie 和 session 的一些事 中间件
cookie 和 session cookie 1. 保存在浏览器上一组组键值对,服务器让浏览器进行设置. 2. 为什么要用cookie? HTTP协议是无状态.使用cookie保存状态. 3. dj ...
- jQuery实现无刷新切换主题皮肤功能
主题皮肤切换功能在很多网站和系统中应用,用户可以根据此功能设置自己喜欢的主题颜色风格,增强了用户体验.本文将围绕如何使用jQuery实现点击无刷新切换主题皮肤功能. 查看演示DEMO:https:// ...
- AtCoder Beginner Contest 045 B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)
Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement Alice, Bob and Charlie ...
- Python学习路线人工智能线性代数知识点汇总
人工智能和数据分析相关的线性代数知识.比如什么是矢量,什么是矩阵,矩阵的加减乘除.矩阵对角化,三角化,秩,QR法,最小二法.等等 矢量: 高中数学中都学过复数,负数表达式是: a+bi 复数实际上和二 ...
- APIClound 弹出层 Frame
JS api.openFrame({ name: 'showPic', url: './showPic.html', rect: { // x: api.pageParam.marginBottom, ...
- nodejs安装淘宝npm镜像【cnpm】
安装完nodejs后[自带npm] 如果npm无法使用或需要FQ,可以先安装cnpm,然后使用cnpm install安装模块 安装全局cnpm npm install -g cnpm --regis ...
- P2P原理及UDP穿透简单说明(转)
源: P2P原理及UDP穿透简单说明
- kivy 小demo
from kivy.lang.builder import Builder from kivy.uix.boxlayout import BoxLayout from kivy.app import ...