注意题意输入粉丝的时候,第i行是第i个关注了谁,而不是他的粉丝。

在遍历的时候也是只转发第一次,所以要一个isVis数组去标记一下。

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <set>#define MAX 1010using namespace std;int n, l;
struct Node {int level;vector <int> follow;Node() { level = 1; }
};
Node list[MAX];
vector <int> s;
bool isVis[MAX];void LevelOrder(int u) {queue <int> q;q.push(u);isVis[u] = true;list[u].level = 1;int topLevel = list[u].level;int NowLevel = topLevel;while (!q.empty()) {int top = q.front();q.pop();NowLevel = list[top].level;if (NowLevel - topLevel < l) {for (int i = 0; i < list[top].follow.size(); i++) {int v = list[top].follow[i];if (!isVis[v]) {list[v].level = NowLevel + 1;q.push(v);isVis[v] = true;s.push_back(v);}}}}
}int main() {cin >> n >> l;int co, t;for (int i = 1; i <= n; i++) {cin >> co;for (int j = 0; j < co; j++) {cin >> t;list[t].follow.push_back(i);}}int m;cin >> m;for (int i = 0; i < m; i++) {cin >> t;memset(isVis, false, sizeof(isVis));s.clear();LevelOrder(t);cout << s.size() << endl;}return 0;
}

1076. Forwards on Weibo 解析相关推荐

  1. PAT甲级1076 Forwards on Weibo (30 分) :[C++题解]图论、bfs

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: BFS如何搜前k层?统计前k层的点数. ac代码 #include<bits/stdc++.h> using names ...

  2. PAT A级 1076 Forwards on Weibo (超详细BFS做法)

    一切杀不死我的,都将使我强大! 1076 Forwards on Weibo(30 分) Weibo is known as the Chinese version of Twitter. One u ...

  3. 1076 Forwards on Weibo

    1. 这题说的是,微博上人们之间有关注和被关注的关系,如果一个人发博,他的追随者就可能转发,追随者的追随者又可能转发,以此类推.现在给定一个人,求其微博可能被转发的人数,但是注意有一个关注链长的上限, ...

  4. 1076 Forwards on Weibo——最后用menset函数

    方法一: #include<cstdio> #include<queue> #include<vector> #include<algorithm> # ...

  5. 1076 Forwards on Weibo (30 分)

    广度搜索BFS 注意理解题意,关注者与被关注者的关系. 同时L是表示,在L层以内的所有节点,包括L层. #include<bits/stdc++.h> using namespace st ...

  6. 【PAT甲级 - C++题解】1076 Forwards on Weibo

    ✍个人博客:https://blog.csdn.net/Newin2020?spm=1011.2415.3001.5343

  7. PAT_甲级_1076 Forwards on Weibo (30point(s)) (C++)【BFS/微博扩散】

    目录 1,题目描述 题目描述 输入 2,思路 BFS算法 3,AC代码 4,解题过程 第一搏 第二搏 1,题目描述 Sample Input: 7 3 3 2 3 4 0 2 5 6 2 3 1 2 ...

  8. 普朗特迈耶稀疏波_埃里克·迈耶的访谈

    普朗特迈耶稀疏波 I've always wanted to interview Eric Meyer. His early CSS books are a big reason this blog ...

  9. PAT (Advanced Level) Practice 题解代码 - II (1051-1100)

    PAT PAT (Advanced Level) Practice - II(1051-1100) -------------------------------------------------- ...

最新文章

  1. linux redis数据库安装配置,Linux系统中redis的安装配置步骤
  2. 你知道Integer和int的区别吗
  3. gentoo hibernate
  4. Calendar类 set方法 get方法 add方法
  5. 实现点击页面其他地方,隐藏div(vue)
  6. 推荐系统系列教程之十六:深度和宽度兼具的融合模型
  7. 使用ComponentOne C1WebGrid控件
  8. 易语言 查询API之文本和字体函数
  9. 柯里化 curry
  10. 小游戏2048最佳算法怎么实现?思路全解析!
  11. linux卡死怎么办
  12. GB2312字符集对应16进制ANSI、UNICODE、UTF-8编码 (5)
  13. JScrollPane设置滚动条自动到最下(或最右)
  14. 猿圈 题库_小猿圈总结常见HTML5基础知识面试题汇总
  15. Mac 蓝牙鼠标卡顿的解决方法
  16. 【考研经验】2018南开计算机技术(专硕)经验 助你一臂之力
  17. Android学习笔记之ViewFlipper
  18. 倍福Twincat NC PTP使用介绍
  19. 知识图谱入门 (九) 知识问答
  20. 你知道怎样做好一个老板吗?先来看看不适合做老板的三种人

热门文章

  1. AutoCAD 突然打不开,显示“VCOMP.DLL”文件缺失,需要重新安装。
  2. Linux的NTP深度学习
  3. AOV网(拓扑排序)和AOE网
  4. Revit 2017 编程需要用Visual Studio2015 +.NET Framework 4.52
  5. SketchUp快捷键
  6. 计算机 等级 三级 网络 题库,计算机等级考试题库,三级网络技术试题,让你久等了!...
  7. Pingo数据库数据导入palo数据库
  8. Catlike Coding系列教材pdf下载
  9. 全景图转局部平面视图原理详解
  10. Linux 常用关闭/重启服务器命令