码迷,mamicode.com
首页 > 其他好文 > 详细

CF1037D Valid BFS?

时间:2019-07-23 15:18:38      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:max   turn   ref   div   ==   title   struct   cout   tar   

https://www.luogu.org/problemnew/show/CF1037D

#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int maxn=100;
struct node{
    int n=0;
    int cnt=0;
    int a[maxn];
};
struct node arr[maxn];
string s1,s2;
void bfs(int s)
{
    queue<node> q;
    q.push(arr[s]);
    while(!q.empty())
    {
        node p=q.front();
        q.pop();
        s1=s1+char(0+p.n);
        if(p.cnt!=0)
        for(int i=0;i<p.cnt;i++)
        {
                q.push(arr[p.a[i]]);
        }
    }
}
int main()
{
    int m,x,y,temp,k;
    cin>>m;
    k=m;
    m--;
    while(m--)
    {
    cin>>x>>y;
    arr[x].n=x;
    arr[x].a[arr[x].cnt]=y;
    arr[x].cnt++;
    arr[y].n=y;
    }
    for(int i=0;i<k;i++)
    {
        cin>>temp;
        s2=s2+char(0+temp);
    }
    bfs(1);
    if(s1==s2)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
 } 

以为是道简单题,其实emmmm

先挖个坑

 

CF1037D Valid BFS?

标签:max   turn   ref   div   ==   title   struct   cout   tar   

原文地址:https://www.cnblogs.com/liuzhaojun/p/11231433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!