【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 ...
 
随机推荐
- python3练习100题——019
			
原题链接:http://www.runoob.com/python/python-exercise-example19.html 题目:一个数如果恰好等于它的因子之和,这个数就称为"完数&q ...
 - 解决windows10  OBS Studioobsstudio显示器捕获黑屏
			
前提设置显卡,下载OBS studio 64bit别下载32bit了 如果电脑desktop右键无法显示NAVIDIA 控制面板则需要win+R 输入 msconfig选取服务,勾选所有NAIVI ...
 - 【算法学习记录-排序题】【PAT A1012】The Best Rank
			
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
 - 快捷键(一):Win10
			
Ctrl + X 剪切选定项 Ctrl + C(或 Ctrl + Insert) 复制选定项 Ctrl + V(或 Shift + Insert) 粘贴选定项 Ctrl + Z 撤消操作 Alt + ...
 - selenium参数化-ddt模块
			
DDT介绍: DDT(数据驱动测试)允许您通过使用不同的测试数据运行一个测试用例来使其倍增,并使它显示为多个测试用例.要使用DDT需要安装,安装命令:pip install ddt 使用方法: dd. ...
 - 【转载】SpringMVC框架介绍
			
转自:http://com-xpp.iteye.com/blog/1604183 SpringMVC框架图 SpringMVC接口解释 DispatcherServlet接口: Spring提 ...
 - execute command denied to user 'maintain'@'%' for routine
			
GRANT ALL PRIVILEGES ON *.* TO 'maintain'@'%' ; FLUSH PRIVILEGES;
 - php商城数据库的设计 之无限分类
			
商品分类,使用无限分类 即: -------如何创建数据表 pid---父级分类id,如果是顶级分类则为0 path---1,用户分类的排序 . 排序示例: 实现逻辑:获取type表的所有分类,ord ...
 - 1+x证书Web 前端开发初级——理论考试(试卷1)
			
1+x证书Web 前端开发初级——理论考试(试卷1) 一.单选题(每小题 2 分,共 30 小题,共 60 分) 1.HTML 语言中,设置表格中文字与边框距离的标签是() A.<table b ...
 - CSP2019感想
			
我觉得自己好弱啊. 想更新博客,可是又没有人看. 本来自己还不算太弱,可是自己越来越腐败. 看看自己,连更新博客的资本都没有了呢.别人写些什么都是经典干货.自己写什么自己都觉得垃圾,只好默默地删掉. ...