题意:

输入两个正整数N和L(N<=1000,L<=6),接着输入N行数据每行包括它关注人数(<=100)和关注的人的序号,接着输入一行包含一个正整数K和K个序号。输出每次询问的人发出消息经过至多L层转发最多有多少人转发。

trick:

逻辑搞错的程序也能得到25或28分。。。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int visit[][];
vector<int>st[];
int l;
int vis[];
int ans;
int last;
int lv[];
void dfs(int x){
queue<int>q;
q.push(x);
vis[x]=;
lv[x]=;
while(!q.empty()){
int now=q.front();
q.pop();
for(auto it:st[now])
if(!vis[it]&&lv[now]<=l){
++ans;
q.push(it);
vis[it]=;
lv[it]=lv[now]+;
}
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n>>l;
for(int i=;i<=n;++i){
int m;
cin>>m;
int x;
for(int j=;j<=m;++j){
cin>>x;
if(!visit[x][i]){
visit[x][i]=;
st[x].push_back(i);
}
}
}
int k;
cin>>k;
for(int i=;i<=k;++i){
if(i>)
for(int j=;j<=n;++j)
vis[j]=,lv[];
ans=;
int x;
cin>>x;
dfs(x);
cout<<ans;
if(i!=k)
cout<<"\n";
}
return ;
}

【PAT甲级】1076 Forwards on Weibo (30 分)的更多相关文章

  1. PAT 甲级 1076 Forwards on Weibo (30分)(bfs较简单)

    1076 Forwards on Weibo (30分)   Weibo is known as the Chinese version of Twitter. One user on Weibo m ...

  2. PAT甲级1076. Forwards on Weibo

    PAT甲级1076. Forwards on Weibo 题意: 微博被称为中文版的Twitter.微博上的一位用户可能会有很多关注者,也可能会跟随许多其他用户.因此,社会网络与追随者的关系形成.当用 ...

  3. PAT Advanced 1076 Forwards on Weibo (30) [图的遍历,BFS,DFS]

    题目 Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and ...

  4. 1076. Forwards on Weibo (30)【树+搜索】——PAT (Advanced Level) Practise

    题目信息 1076. Forwards on Weibo (30) 时间限制3000 ms 内存限制65536 kB 代码长度限制16000 B Weibo is known as the Chine ...

  5. PAT甲级——1131 Subway Map (30 分)

    可以转到我的CSDN查看同样的文章https://blog.csdn.net/weixin_44385565/article/details/89003683 1131 Subway Map (30  ...

  6. PAT 甲级 1068 Find More Coins (30 分) (dp,01背包问题记录最佳选择方案)***

    1068 Find More Coins (30 分)   Eva loves to collect coins from all over the universe, including some ...

  7. PAT 甲级 1045 Favorite Color Stripe (30 分)(思维dp,最长有序子序列)

    1045 Favorite Color Stripe (30 分)   Eva is trying to make her own color stripe out of a given one. S ...

  8. PAT 甲级 1018 Public Bike Management (30 分)(dijstra+dfs,dfs记录路径,做了两天)

    1018 Public Bike Management (30 分)   There is a public bike service in Hangzhou City which provides ...

  9. PAT 甲级 1014 Waiting in Line (30 分)(queue的使用,模拟题,有个大坑)

    1014 Waiting in Line (30 分)   Suppose a bank has N windows open for service. There is a yellow line ...

随机推荐

  1. [P4549] 【模板】裴蜀定理 - GCD

    __gcd真好用 #include <bits/stdc++.h> using namespace std; int main() { int n,x,a=0; cin>>n; ...

  2. SpringMVC进行Ajax请求页面显示乱码

    最近在项目的使用过程中发现在springmvc的项目中,使用返回页面的请求方式,数据都能正常显示,但是对于ajax的请求,始终显示乱码. 首先第一种是因为我们在web.xml中配置了spring的字符 ...

  3. Spring家族几大插件

    Spring家族很庞大,从最早先出现的服务于企业级程序开发的Core.安全方面的Security.到后来的作为各种数据源桥梁的Data.最近几年很火的Boot,以及最新推出的正在蓬勃发展的Cloud( ...

  4. django入门与实践(续)

    完善博客 博客页面设计 页面概要 1.博客主页面 主页面内容 文章标题列表,超链接 发表博客按钮(超链接) 列表编写思路 取出数据库中所有文章对象 将文章对象们打包成列表,传递到前端 前端页面把文章以 ...

  5. 0215 docker环境

    docker的下载安装和基本使用 我使用的mac,直接安装desktop. 然后命令行使用docker,关于desktop的使用,可以看官方文档. 安装好之后,确认一下是否可以运行,输入docker ...

  6. electron聊天室|vue+electron-vue仿微信客户端|electron桌面聊天

    一.项目概况 基于Electron+vue+electron-vue+vuex+Nodejs+vueVideoPlayer+electron-builder等技术仿制微信电脑端界面聊天室实例,实现消息 ...

  7. vuecli+axios的post请求传递参数异常

    大多数的web服务器只能识别form的post的请求,即请求头Content-Type为’application/x-www-form-urlencoded‘ axios.defaults.heade ...

  8. Java-POJ1003-Hangover

    题目大意: 给出一个浮点数a,求出使得 不等式 1/2 + 1/3 + ... + 1/(n+1) ≥ a 成立的最小值 大水题,由于数据范围小,给出了确认上界5.20,满足二分答案 但是我懒啊,直接 ...

  9. 以管理员身份运行 Microsoft Edge 时不支持登录

    之前一直用 edge chromium bate版本 一直不能登录 今天试了正式版 还是这样 然后百度一大堆没找到解决方案 设置兼容性为windown7 是可以的 但是 UI显示会有问题 再次打开 又 ...

  10. Apache Kafka(十二)Log Cleanup 策略

    Log Cleanup 策略 在Kafka中,存在数据过期的机制,称为data expire.如何处理过期数据是根据指定的policy(策略)决定的,而处理过期数据的行为,即为log cleanup. ...