Write a program that searches a directed graph for vertices which are inaccessible from a given starting vertex.
    A directed graph is represented by n vertices where 1 ≤ n ≤ 100, numbered consecutively 1 . . . n , and a series of edges p -> q which connect the pair of nodes p and q in one direction only.
    A vertex r is reachable from a vertex p if there is an edge p -> r, or if there exists some vertex q for which q is reachable from p and r is reachable from q.
    A vertex r is inaccessible from a vertex p if r is not reachable from p.
Input
The input data for this program consists of several directed graphs and starting nodes.
    For each graph, there is first one line containing a single integer n. This is the number of vertices in the graph.
    Following, there will be a group of lines, each containing a set of integers. The group is terminated by a line which contains only the integer ‘0’. Each set represent a collection of edges. The first integer in the set, i, is the starting vertex, while the next group of integers, j . . . k, define the series of edges i -> j . . . i -> k, and the last integer on the line is always ‘0’. Each possible start vertex i, 1 ≤ i ≤ n will appear once or not at all. Following each graph definition, there will be one line containing a list of integers. The first integer on the line will specify how many integers follow. Each of the following integers represents a start vertex to be investigated by your program. The next graph then follows. If there are no more graphs, the next line of the file will contain only the integer ‘0’.
Output
For each start vertex to be investigated, your program should identify all the vertices which are inaccessible from the given start vertex. Each list should appear on one line, beginning with the count of inaccessible vertices and followed by the inaccessible vertex numbers.
Sample Input
3
1 2 0
2 2 0
3 1 2 0
0
2 1 2
0
Sample Output
2 1 3
2 1 3

问题链接:UVA280 LA5588 Vertex
问题简述:统计一个有向图中,指定结点不能到达的结点。
问题分析:用DFS来实现,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA280 LA5588 Vertex */#include <bits/stdc++.h>using namespace std;const int N = 100 + 1;
int g[N][N], vis[N], cnt;void dfs(int n, int u)
{for (int v = 1; v <= n; v++)if (g[u][v] == 1 && vis[v] == 0) {vis[v] = 1;cnt--;dfs(n, v);}
}int main()
{int n, u, v;while (cin >> n && n) {memset(g, 0, sizeof g);while (cin >> u && u)while (cin >> v && v)g[u][v] = 1;int num;cin >> num;for (int i = 1; i <= num; i++) {cin >> u;memset(vis, 0, sizeof vis);cnt = n;dfs(n, u);cout << cnt;for (int j = 1; j <= n; j++)if (vis[j] == 0) {if (cnt) cout << " ";cout << j;cnt--;}cout << endl;}}return 0;
}

UVA280 LA5588 Vertex【DFS】相关推荐

  1. Bailian2815 城堡问题【DFS】

    2815:城堡问题 总时间限制: 1000ms 内存限制: 65536kB 描述 1 2 3 4 5 6 7 ############################# 1 # | # | # | | ...

  2. Bailian2816 红与黑【DFS】

    2816:红与黑 总时间限制: 1000ms 内存限制: 65536kB 描述 有一间长方形的房子,地上铺了红色.黑色两种颜色的正方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动.请写一 ...

  3. NUC1158 Lake Counting【DFS】

    Lake Counting 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 Due to recent rains, water has pooled ...

  4. NUC1399 Sum It Up【DFS】

    Sum It Up 时间限制: 1000ms 内存限制: 65535KB 通过次数: 1总提交次数: 1 问题描述 Given a specified total t and a list of n ...

  5. HDU1181 变形课【DFS】(废除)

    新题解参见:HDU1181 变形课[DFS+关系闭包+bitset] 变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 13107 ...

  6. 【DFS】巧妙取量的倒油问题

    题目描述 [题目描述]  有三个容器,容量分别为 a,b,c(a> b > c ),一开始a装满油,现在问是否只靠abc三个容器量出k升油.如果能就输出"yes",并且 ...

  7. [kuangbin]专题三 Dancing Links Squiggly Sudoku HDU - 4069【DFS】【精确覆盖】

    [题目描述] Today we play a squiggly sudoku, The objective is to fill a 9*9 grid with digits so that each ...

  8. 【DFS】不撞南墙不回头—深度优先搜索算法[Deep First Search]

    今天上午听到,那个非常6+1的李咏先生因癌症去世 DFS算法的基本模型 深度下,不撞南墙不回头,就是一直往后找,知道没有路了,向后返回. 想起一首民谣,<可能否>--木小雅 https:/ ...

  9. NUC1333 Knight Moves【DFS】

    Knight Moves 时间限制: 1000ms 内存限制: 65535KB 问题描述 A friend of you is doing research on the Traveling Knig ...

最新文章

  1. computer vision(计算机视觉)方面的期刊会议,学术必备
  2. 组图:1904年圣路易斯奥运会
  3. HNCU 1328: 算法2-18~2-19:双向循环链表
  4. axios获取header中的信息_Axios请求头中常见的Content-Type及其使用
  5. 会计转行从事IT,如何在一年时间内全职学习?
  6. 【POJ - 2019】Cornfields(二维st表,模板)
  7. python列表切片和推导式思维导图_Python列表推导式使用
  8. get 与 post的区别?application json 与form表单的区别?
  9. Openstack Object Store(Swift)设置公有存储的方法
  10. B站 React教程笔记day1(4)调色板案例
  11. Matlab学习1-图像处理灰度
  12. 攻防世界web练习区
  13. cortex系列处理器排行_ARM Cortex-M 处理器家族介绍和比较-控制器/处理器-与非网...
  14. Android 显示后台返回富文本rgb色值适配问题
  15. 榆熙电商:在拼多多开网店如何计算产品价格弹性区间?
  16. Nao机器人运行B-human代码之开始篇 1
  17. Windows系统的电脑有可以删除的文件夹(个人笔记)
  18. 拔山盖世(BSGS)算法
  19. 数学建模学习1.22——多元回归分析
  20. 极速pdf文件打印时此计算机未连接到网络,PDF文件不能打印的五种解决方案

热门文章

  1. 2021-08-26 转载 Scala快速入门系列博客文章
  2. mysql——event定时任务
  3. Flash: 涅磐与重生
  4. CAsyncSocket使用总结
  5. php 保存错误日志,PHP中把错误日志保存在系统日志中_PHP教程
  6. 虚拟机centos7 git clone特别慢_从文件生命周期看GIT的提交流程
  7. Java常量什么时候被回收,JVM GC调优(2)-GC算法判定对象可以被回收(部分摘自深入理解Java虚拟机) - Java 技术驿站-Java 技术驿站...
  8. stringstream常见用法介绍
  9. Python基础——pickle(保存与提取数据)
  10. LeetCode35. 搜索插入位置(二分查找)