当前位置:网站首页>1076 forwards on Weibo (30 points)
1076 forwards on Weibo (30 points)
2022-07-22 20:34:00 【Konjaku for learning programming】
1076 Forwards on Weibo (30 branch )
Update ideas when available
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
vector<int> v[1050];
int n, l, k, x, m, vis[1050];
int bfs(int x){
int level = 0, ret = 0;
queue<int> q;
q.push(x);
vis[x] = 1;
while(!q.empty() && level < l){
int size = q.size();
for(int i = 0; i < size; ++i){
int a = q.front();
for(int j = 0; j < v[a].size(); ++j){
if(!vis[v[a][j]]){
q.push(v[a][j]);
vis[v[a][j]] = 1;
ret++;
}
}
q.pop();
}
level++;
}
return ret;
}
int main() {
cin >> n >> l;
for(int i = 1; i <= n; ++i) {
cin >> m;
while(m--) {
cin >> x;
v[x].push_back(i);
}
}
cin >> k;
while(k--) {
memset(vis, 0, sizeof vis);
cin >> x;
cout << bfs(x) << endl;
}
}
边栏推荐
- 1053 Path of Equal Weight (30 分)
- MySQL query blob
- 数据从一台Mysql传输到另一台Mysql
- Canny based subpixel severity algorithm
- 《强化学习周刊》第39期:近似最优深度、多智能体广义、角色动画强化学习
- LeetCode206——反转链表
- Dense Passage Retrieval for Open-Domain Question Answering笔记
- 她力量系列五丨朱海一:以人为本,构建 AI 价值观
- LeetCode103——zigzagLevelOrder of binary tree
- "Pre training weekly" No. 38: transformer, Bert structure optimization
猜你喜欢
Signal noise reduction method
她力量系列三丨把握当下,坚持热爱,与食物图像识别结缘的科研之路
她力量系列四丨读博6年两次换导师,靠一点点“倔”,俞舟成为social chatbot的开拓者之一
YOLO v1、v2、v3
进程fork
json按格式逐行输出到文件
JSON output to file line by line in format
IDEA 隐藏.idea文件夹 隐藏.iml文件
Causal learning weekly, issue 10: introduction to the latest causal discovery related papers in iclr2022
她力量系列五丨朱海一:以人为本,构建 AI 价值观
随机推荐
Leetcode0022 - bracket generation - DFS
【面试:基础篇02:冒泡排序】
AMBert
c语言unsigned int和int
flask 跨域
LeetCode21——Merge two sorted lists——Iteration or recursion
LeetCode160 & LeetCode141——double pointers to solve the linked list
LeetCode53——Maximum Subarray——3 different methods
正则表达式学习笔记
CSDN博客去除上传的图片水印
On the horizontal trigger and edge trigger of epoll
VIM uses tips
LeetCode146——LRU Cache——DS Design
VSCODE 比较两个文件
Leetcode206 - reverse linked list
LeetCode53——Maximum Subarray——3 different methods
本地镜像发布到阿里云
YOLO v1、v2、v3
Signal noise reduction method
进程fork