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 ...
随机推荐
- resultType没有指定就会报错
报错如下: 改正方式就是添加resultType. org.apache.ibatis.executor.ExecutorException: A query was run and no Resul ...
- JVM安全退出(如何优雅的关闭java服务)
https://tech.imdada.cn/2017/06/18/jvm-safe-exit/?utm_source=tuicool&utm_medium=referral 背景 用户:货都 ...
- Sql Server 中关于@@ERROR的一个小小误区
我们经常写存储过程的时候会用到@@ERROR来判断执行是否成功,很久没有写复杂点的存储过程了,今天发现前段时间写的一个proc出现了bug,由于定义参数时,字符串长度设的有点短,导致传进来的值中间被截 ...
- C++空类和string类
1. 空类 1.1 空类默认哪六个成员函数. class Empty { public: Empty(); //缺省构造函数 Empty e; Empty( const Empty& ); / ...
- 控制语句1:真假与if 语句
一.真假与运算符 1.1 真假的划分.查看 任何数据都可以分为两类:True 与 False False : 0,None,空的数据结构例如:[] ,{},str1 = '' True :除了上面情 ...
- 【scala】apply和update
我们在使用scala的时候经常会用到对象的apply方法和update方法. 虽然我们表面没有察觉,但是实际上两个方法都会遵循相关约定被调用. apply apply方法的约定:用括号传递给变量(对象 ...
- LeetCode OJ:Spiral MatrixII(螺旋矩阵II)
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- 《Drools7.0.0.Final规则引擎教程》第4章 4.2 activation-group& dialect& date-effective
activation-group 该属性将若干个规则划分成一个组,统一命名.在执行的时候,具有相同activation-group 属性的规则中只要有一个被执行,其它的规则都不再执行.可以用类似sal ...
- OpenGL ES 2: debugging, and improvements to VAO, VBO
OpenGL ES 2: debugging, and improvements to VAO, VBO http://www.altdevblogaday.com/2013/10/12/opengl ...
- Windows10使用Chocolatey安装mysql之后无法使用的解决办法
问题背景:使用了一台新的虚拟机,并且安装了Chocolatey作为Windows的包管理器,之后安装mysql 那么问题发生了,使用mysql命令根本没有任何反应,也不报错,但是安装的时候是提示安装成 ...