1146 Topological Order
题意:判断序列是否为拓扑序列。
思路:理解什么是拓扑排序就好了,简单题。需要注意的地方就是,因为这里要判断多个,每次判断都会改变入度indegree[],因此记得要把indegree[]留个备份。ps.这是第一次考到拓扑序列,我觉得9月8号会考如何求一个拓扑序列,外加求关键路径!?详见:图算法的总结
代码:
#include <cstdio>
#include <vector>
using namespace std;
;
vector<int> adj[maxn];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
vector<),temp;
int u,v;
;i<m;i++){
scanf("%d%d",&u,&v);
adj[u].push_back(v);
indegree[v]++;
}
int query;
scanf("%d",&query);
vector<int> ans;
;i<query;i++){
bool flag=true;
temp=indegree;//初始化,注意每一轮判断前都先赋值,因为每一轮都会改动结点的入度
;j<n;j++){
scanf("%d",&u);
&& flag){
//遍历结点u的所有出边,把相应的结点入度减1
;k<adj[u].size();k++)
temp[adj[u][k]]--;
}else{
flag=false;
}
}
if(flag==false) ans.push_back(i);
}
;i<ans.size();i++){
printf("%d",ans[i]);
) printf(" ");
}
;
}
1146 Topological Order的更多相关文章
- 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 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1146 Topological Order
https://pintia.cn/problem-sets/994805342720868352/problems/994805343043829760 This is a problem give ...
- [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
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- 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 (25分)
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- A1146. Topological Order
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- 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 ...
随机推荐
- JNIjw01
1.VC6(CPP)的DLL代码: #include<stdio.h> #include "jniZ_JNIjw01.h" JNIEXPORT void JNICALL ...
- LeetCode第[54]题(Java):Spiral Matrix
题目:螺旋矩阵 难度:Medium 题目内容: Given a matrix of m x n elements (m rows, n columns), return all elements of ...
- tensorflow笔记:模型的保存与训练过程可视化
tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 ...
- vue开发者工具DejaVue
刚刚在逛github的时候发现了一个vue开发工具觉得很不错,分享给v友们! 地址:https://github.com/MiCottOn/DejaVue 话不多说,直接说操作流程!(前提是node版 ...
- 【scala】构造器
和Java或C++一样,Scala可以有任意多的构造器. 不过Scala类有一个构造器比其他所有构造器都更为重要,它就是主构造器. 除了主构造器之外,类还可以有任意多的辅助构造器. 主构造器 在Sca ...
- XML的两种解析方式
JDK提供的XML解析方式分为两种:DOM方式和SAX方式DOM:Document Object Model.需要读取整个XML文档,先需要在内存中构架代表整个DOM树的Document对象,可以进行 ...
- 【.Net】Socket小示例
引言 项目中用到了Socket,这里做个控制台小示例记录一下. Client 客户端的Receive用了异步方法,保持长连接,可以随时发送消息和响应服务端的消息,如下 static string Cl ...
- shell编程学习1
1.shell是操作系统的终端命令行 (1)shell可以理解为软件系统提供给用户操作的命令行界面,可以说它是人机交互的一种方式. (2)我们可以使用shell和操作系统.uboot等软件系统进 ...
- UICollectionView-网格视图
1. UICollectionView 网格视图,除了提供与UITableView同样的功能显示一组顺序显示的数据,还支持多列的布局. 2. UICollectionView 使用 > 设置Co ...
- 你不知道的sticky
position:sticky,Chrome新版本已经做了支持.sticky的中文翻译是“粘性的”,position:sticky表现也符合这个粘性的表现.基本上,可以看出是position:rela ...