当前位置:网站首页>1076 Forwards on Weibo (30 分)
1076 Forwards on Weibo (30 分)
2022-07-22 10:33:00 【学编程的蒟蒻】
1076 Forwards on Weibo (30 分)
思路有空更新
#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;
}
}
边栏推荐
- Introduction to machine learning: linear regression-1
- Mutual exclusion and synchronization of processes
- redis集群搭建
- How to repair DNS hijacking perfectly? How to solve DNS hijacking and how to repair it perfectly
- 本地镜像发布到私有库
- Chen Danqi: I hope girls can get more opportunities, and the gap between boys and girls will gradually disappear
- IDEA 隐藏.idea文件夹 隐藏.iml文件
- CentOS安装mysql数据库
- 网站安全之域名被劫持、域名被劫持后该怎么办!!!
- flask 跨域
猜你喜欢
Her power series seven LAN Yanyan: ideal warm 10-year scientific research road, women can be gentle, more confident and professional | women's Day Special
LeetCode21——Merge two sorted lists——Iteration or recursion
LeetCode0022——括号生成——DFS
Her power series III holds the current, adheres to love, and is tied to the scientific research road of food image recognition
How to deal with DNS hijacked? Five ways to deal with it
How to repair DNS hijacking perfectly? How to solve DNS hijacking and how to repair it perfectly
What should I do if the web page is hijacked? How to repair DNS hijacked? Introduction to web hijacking
《因果学习周刊》第10期:ICLR2022中最新Causal Discovery相关论文介绍
Classic cases of semaphore synchronization and mutual exclusion
机器学习入门:支持向量机-6
随机推荐
CPU affinity
LeetCode0022——括号生成——DFS
mysql引擎
LeetCode146——LRU Cache——DS Design
LeetCode21——Merge two sorted lists——Iteration or recursion
LeetCode912——sort an array—— quick sort algorithm
网站莫名跳转,从百度谈什么是网站劫持?百度快照劫持怎么解决
Deep understanding of MMAP function
Typora download and simple use tutorial
linux安装oracle XE
How to deal with DNS hijacked? Five ways to deal with it
CPU亲和力
dns被劫持了怎么处理 5种方法教你处理
LeetCode206——反转链表
深入理解mmap函数
IDEA 隐藏.idea文件夹 隐藏.iml文件
笔记:C语言
What does Baidu snapshot hijacking mean? How to solve Baidu snapshot hijacking and Baidu hijacking
redission分布式锁种类
yum安装提示保护多库版本