PAT (Advanced) 1076. Forwards on Weibo (30)
来源:互联网 发布:sql server企业管理器 编辑:程序博客网 时间:2024/06/05 23:54
#include <iostream>#include <cstring>using namespace std;const int MAX = 1000;bool edge[MAX][MAX];bool visited[MAX];int queue[MAX];int BFS(int start, int n, int level){int res = 0;int front = 0, rear = 1, level_last;queue[front] = start;visited[start] = true;while (front < rear){level_last = rear;level--;while (front < level_last){int i = queue[front++];for (int j = 0; j < n; j++){if (!visited[j] && edge[i][j]){visited[j] = true;res++;queue[rear++] = j;}}}if (level == 0)break;}return res;}int main(){int N, L;cin >> N >> L;int M, s;for (int i = 0; i < N; i++){cin >> M;for (int j = 0; j < M; j++){cin >> s;edge[s - 1][i] = true;}}int K;int start;int sum;cin >> K;for (int i = 0; i < K; i++){memset(visited, false, sizeof(visited));cin >> start;cout << BFS(start - 1, N, L) << endl;}}
0 0
- PAT (Advanced) 1076. Forwards on Weibo (30)
- PAT Advanced Level 1076. Forwards on Weibo (30)
- 【PAT】【Advanced Level】1076. Forwards on Weibo (30)
- PAT (Advanced Level) Practise 1076 Forwards on Weibo (30)
- PAT (Advanced Level) Practise 1076 Forwards on Weibo (30)
- PAT A 1076. Forwards on Weibo (30)
- PAT-1076. Forwards on Weibo (30)
- pat 1076. Forwards on Weibo (30)
- PAT 1076. Forwards on Weibo (30)
- PAT 1076. Forwards on Weibo (30)
- PAT 1076. Forwards on Weibo (30)
- 【PAT】 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30) PAT
- PAT(A) - 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30) PAT 甲级
- PAT-A-1076. Forwards on Weibo (30)
- 【PAT甲级】1076. Forwards on Weibo (30)
- Pat(A) 1076. Forwards on Weibo (30)
- systemparametersinfo详细
- Java特点
- 增加slogan
- 第一次作业:计算“两个整数的最大公约数”程序
- 常用排序算法C语言实现
- PAT (Advanced) 1076. Forwards on Weibo (30)
- cocos2d-x 标签加黑边和阴影
- 为什么说很多人说用ASP.NET开发小型网站是杀鸡焉用牛刀?
- HDU 3746 Cyclic Nacklace KMP
- swt转exe
- lua表的遍历-易错点
- 兼容sdk7&iOS7的issue解决小片段总结
- Pearson(皮尔逊)相关系数及MATLAB实现
- Codeforces Round #129 (Div. 1) B. Little Elephant and Cards