PAT1076 Forwards on Weibo

原文:我的个人博客

原题链接

1076 Forwards on Weibo

考点

  图的遍历,广度优先遍历

思路

  简单的广搜就可以解决。在广搜的过程中记录所在的层次。

代码

#include 
using namespace std;
vector net[10010];
bool visit[10010];
int n,L,k,tmp;
int cnt=0;
struct node{
    int key;
    int layer;
};
 
void bfs(int root){
    queueq;
    q.push(node{root,0});
    int layer=L;
    visit[root] = true;
    while(!q.empty()){
        node now = q.front();
        q.pop();
        for(int i=0;i>n>>L;
    for(int i=1;i<=n;i++){
        cin>>k;
        for(int j=0;j>tmp;//ta
            net[tmp].push_back(i);
        }
    }
    int q;
    cin>>q;
    for(int i=0;i>tmp;
        fill(visit,visit+10010,false);
        cnt=0;
        bfs(tmp);
        cout<

 

你可能感兴趣的:(PAT,算法)