1146. Topological Order (25)
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options.
Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers N (<= 1,000), the number of vertices in the graph, and M (<= 10,000), the number of directed edges. Then M lines follow, each gives the start and the end vertices of an edge. The vertices are numbered from 1 to N. After the graph, there is another positive integer K (<= 100). Then K lines of query follow, each gives a permutation of all the vertices. All the numbers in a line are separated by a space.
Output Specification:
Print in a line all the indices of queries which correspond to "NOT a topological order". The indices start from zero. All the numbers are separated by a space, and there must no extra space at the beginning or the end of the line. It is graranteed that there is at least one answer.
Sample Input:
- 6 8
- 1 2
- 1 3
- 5 2
- 5 4
- 2 3
- 2 6
- 3 4
- 6 4
- 5
- 1 5 2 3 6 4
- 5 1 2 6 3 4
- 5 1 2 3 6 4
- 5 2 1 6 3 4
- 1 2 3 4 5 6
Sample Output:
- 3 4
- 开门见山的题。
代码:
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <map>
- #define Max 1005
- using namespace std;
- int n,m,k,limit[Max],exa[Max],a,b,mp[Max][Max],ans[Max],ant;///limit存某个点前面有几个点先行
- int check()
- {
- int p[Max];
- for(int i = ;i <= n;i ++)///limit转到p
- {
- p[i] = limit[i];
- }
- for(int i = ;i < n;i ++)
- {
- if(p[exa[i]])///p为正表示顺序不合法
- {
- return ;
- }
- for(int j = ;j <= n;j ++)///如果合法 把受它限制的点 p都减1
- {
- if(mp[exa[i]][j])p[j] --;
- }
- }
- return ;
- }
- int main()
- {
- scanf("%d%d",&n,&m);
- for(int i = ;i < m;i ++)
- {
- scanf("%d%d",&a,&b);
- mp[a][b] = ;
- limit[b] ++;
- }
- scanf("%d",&k);
- for(int i = ;i < k;i ++)
- {
- for(int j = ;j < n;j ++)
- {
- scanf("%d",&exa[j]);
- }
- if(!check())
- {
- ans[ant ++] = i;
- }
- }
- for(int i = ;i < ant;i ++)
- {
- if(i)printf(" %d",ans[i]);
- else printf("%d",ans[i]);
- }
- }
1146. Topological Order (25)的更多相关文章
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT甲级——1146 Topological Order (25分)
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- PAT 1146 Topological Order[难]
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which o ...
- [PAT] 1146 Topological Order(25 分)
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- PAT 甲级 1146 Topological Order
https://pintia.cn/problem-sets/994805342720868352/problems/994805343043829760 This is a problem give ...
- PAT 1146 Topological Order
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- 1146 Topological Order
题意:判断序列是否为拓扑序列. 思路:理解什么是拓扑排序就好了,简单题.需要注意的地方就是,因为这里要判断多个,每次判断都会改变入度indegree[],因此记得要把indegree[]留个备份.ps ...
- PAT_A1146#Topological Order
Source: PAT A1146 Topological Order (25 分) Description: This is a problem given in the Graduate Entr ...
- PAT A1146 Topological Order (25 分)——拓扑排序,入度
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
随机推荐
- eclipse jshint安装
http://www.cnblogs.com/lhb25/archive/2012/04/05/javascript-validation-with-jshint-eclipse.html
- 《SQL Server 2012 T-SQL基础》读书笔记 - 8.数据修改
Chapter 8 Data Modification SQL Server 2008开始,支持一个语句中插入多行: INSERT INTO dbo.Orders (orderid, orderdat ...
- 在Ubuntu16.04下安装SourceInsight和WeChat
1 使用Wine安装SourceInsight4 1.1 安装Wine $ sudo apt-get install wine 1.2 安装SourceInsight 下载SourceInsight软 ...
- loj#6036 编码
分析 考虑trie+2sat 每次将?=0和?=1的分别插入 插入串时将这个点的选择状态和前缀的选择状态连关系边 注意串结束时建一个新点表示当前串 最后跑2sat即可 代码 #include<b ...
- 008-elasticsearch5.4.3【二】ES使用、ES客户端、索引操作【增加、删除】、文档操作【crud】
一.ES使用,以及客户端 1.pom引用 <dependency> <groupId>org.elasticsearch.client</groupId> < ...
- Windows Server 2008 R2 为用户“IIS APPPOOL\DefaultAppPool”授予的权限不足,无法执行此操作
报表开发与部署好后,也嵌入到aspx页面中了,使用VS自带的Web服务器组件,一切正常,当部署到IIS中的时,出现了如下错误: 为用户“IIS APPPOOL\DefaultAppPool”授予的权限 ...
- 测开之路九十七:js的引用方式
第一种:引用外部js文件 准备一个js文件 <!-- 引用外部的js --><script src="../js/js01.js"></script& ...
- python 列表、字典多排序问题
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/justin051/article/det ...
- oracle--goldengate安装实例
goldengate命令汉语解析地址:https://blog.csdn.net/eadela/article/details/102668879 实例地址:https://www.jianshu.c ...
- C语言1-2019级秋季作业第一周作业
1.你对软件工程专业或者计算机科学与技术专业了解是怎样? 软件工程专业是指对计算机的软件方面灵活掌控,开发软件的工程.软件工程其中会用到计算机科学.数学方面构建模型与算法:软件工程的目标就是开发出能够 ...