【PAT甲级】1076 Forwards on Weibo (30 分)
题意:
输入两个正整数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 分)的更多相关文章
- 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 ...
- PAT甲级1076. Forwards on Weibo
PAT甲级1076. Forwards on Weibo 题意: 微博被称为中文版的Twitter.微博上的一位用户可能会有很多关注者,也可能会跟随许多其他用户.因此,社会网络与追随者的关系形成.当用 ...
- 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 ...
- 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 ...
- PAT甲级——1131 Subway Map (30 分)
可以转到我的CSDN查看同样的文章https://blog.csdn.net/weixin_44385565/article/details/89003683 1131 Subway Map (30 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- [HEOI2016] 字符串 - 后缀数组,主席树,ST表,二分
[HEOI2016] 字符串 Description 给定一个字符串 \(S\), 有 \(m\) 个询问,每个询问给定参数 \((a,b,c,d)\) ,求 \(s[a..b]\) 的子串与 \(s ...
- PP: Overviewing evolution patterns of egocentric networks by interactive construction of spatial layouts
Problem: get an overall picture of how ego-networks evolve is a common challenging task. Existing te ...
- 是未来还是“有毒”?紧抓球鞋风口的毒APP机遇与危机并存
编辑 | 于斌 出品 | 于见(mpyujian) 新一代的"潮流"之风正在席卷新生代消费市场,从去年开始,国内二手球鞋交易领域突然开始火爆,大有成为新一轮"风口&quo ...
- 执行PDB的PITR恢复失败的说明
Oracle 12.1版本中,UNDO表空间仅存在CDB级别(共享UNDO),来自于AskScuti博客园. Oracle 12.2版本开始,UNDO表空间同时可以存在每个PDB级别(本地UNDO). ...
- h264 RTP STAP-A单时间聚合包
参考官方文档:http://www.rosoo.net/Files/UpFiles/RsProduct/avtools/2009-4/2009491562537854.txt 聚合包的RTP荷载格式的 ...
- [C语言学习笔记四]变量与系统的交互
使用 const 创建常量和使用 volatie 优化变量 C语言中使用 const 定义常量. 例如: const INT a = 10; 此处如果添加a = 20;,编辑器则会报错,因为此处 a ...
- python 操作 word 图片 消失
问题描述修改word中文本,如下代码,保存时会导致word中的部分图片消失 from docx import Document path1 = 'test_in.docx' path2 = 'test ...
- Django_模型
1. ORM 2. 简单使用 3. 外键 2.0以上的版本要这样写s_grade = models.ForeignKey(Grade,on_delete=models.CASCADE) 3. 修改表名 ...
- Spark On Yarn搭建及各运行模式说明
之前记录Yarn:Hadoop2.0之YARN组件,这次使用Docker搭建Spark On Yarn 一.各运行模式 1.单机模式 该模式被称为Local[N]模式,是用单机的多个线程来模拟Spa ...
- 7_3 分数拆分(UVa10976)<缩小枚举范围>
每一个(k>0)这种形式的分数我们总是可以找到2个正整数x和y(x >= y),使得:现在我们的问题是:给你k,请你写一个程序找出所有的x和y.Input输入含有多组测试数据(不会超过10 ...