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 ...
随机推荐
- CG-CTF | 上传绕过
最近一直在做算法题,头都要大了,今天悄咪咪来一个web换换脑子,一发flag敲开♥[虽然知道这是个水题ε=ε=ε=┏(゜ロ゜;)┛]
- 5.React中组件通信问题
1.父组件传递值给子组件 想必这种大家都是知道的吧!都想到了用我们react中的props,那么我在这简单的写了小demo,请看父组件 class Parent extends Component{ ...
- 数据库为什么使用B+树而不是B树
B树和B+树的区别主要有两点: 在B树中,你可以将键和值存放在内部节点和叶子节点,但在B+树中,内部节点都是键,没有值.叶子节点同时存放键和值 B+树的叶子节点有一条链相连,而B+树的叶子节点各自独立 ...
- svn 服务器操作
mkdir /var/svn/svnrepos/aaasvnadmin create /var/svn/svnrepos/aaasvnserve -d -r /var/svn/svnrepos #启动 ...
- ParaEngine 一个同事的公司的开源引擎
看说明作者是李西峙,浙大研究生,靠投资研发此引擎,10年了,大概翻了下github里的文件,值得收藏,至少里面有voxelmesh https://github.com/LiXizhi/NPLRunt ...
- loj#6157 A ^ B Problem
分析 用并查集维护 每次一个连通块的每个点记录它到当前连通块的根的异或值 对于不符合的情况容易判断 最后判断是否都在一个连通块内然后记录答案即可 代码 #include<bits/stdc++. ...
- 十六、简单配置jenkins执行本地的robotframework项目
A.前期准备: 1.登录jenkins 2.系统管理-插件管理-高级-上传插件(http://mirrors.jenkins-ci.org/plugins/robot/,中选择一个版本的插件下载至本地 ...
- Vue实现音乐播放器(六):jsonp的应用+抓取轮播图数据
用jsonp来获取数据 通过封装方法来获取 在src文件夹下的api文件夹里面去封装一些获取相关部分组件的数据的方法 在api文件夹下的recommend.js中 配置一下公共参数 请求的真实的u ...
- MyEclipse/Eclipse启动时workspace不提示,解决办法
右键MyEclipse/Eclipse的快捷方式,选择属性(属性->快捷方式->目标),在目标的最后面加上" -clean",如:"D:\Myeclipse8 ...
- 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_01 File类_7_File类创建删除功能的方法
createNewFile() createNewFile抛出了异常 抛出了一个IO异常 所有我们调用方法的时候必须处理异常 throws这个异常 返回结果为true 最终创建好的文件 再次执行代码. ...