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 ...
随机推荐
- postgresql centos6.5安装以及常用命令
今天在centos6.5下安装postgresql数据库,现在整理自己操作步骤. 一. Centos6.5 下安装postgresql9.4 1.1. 显示所有的有关postgresql安装包 yum ...
- is(':visible')
.end()为结束前面处理函数,返回到最初的元素 .next()为此元素的下一个元素,可以再加上.next()表示下下一个元素,以此类推 :visible 选择器选取每个当前是可见的元素.语法:$(& ...
- S3C2440启动方式
不管S3C2440的启动设备是什么,它都是从0x0000 0000地址开始执行程序的,所不同的是地址的映射不一样.基于S3C2440的嵌入式系统上电之后,需要首选选择启动设备,2440的启动方式选择是 ...
- ajax用json实现数据传输
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族 ...
- EL表达式自定义函数
表达式语言除了可以使用基本的运算符外,还可以使用自定义函数.通过使用自定义函数,加强了表达式语言的功能. EL表达式函数,主要功能是完成对数据的修改,统一化格式: 步骤 1.开发函数处理类,处理类就是 ...
- LeetCode OJ:Longest Common Prefix(最长公共前缀)
Write a function to find the longest common prefix string amongst an array of strings. 求很多string的公共前 ...
- LeetCode OJ:Remove Duplicates from Sorted Array(排好序的vector去重)
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- Juint 单元测试(2)
单元测试(junit testing),是指对软件中的最小可测试单元进行检查和验证.Java里单元指一个类. JUnit ,是一个开源的Java单元测试框架,是 Java的标准单元测试库,是非常重要第 ...
- 微信小程序如何在使用wx.request使用cookie
我主要是做asp.net mvc后端开发的,经常使用Jquery的ajax与后台的Web API进行数据交互. 最近公司要做一个小程序,要实现小程序与Web前端的通信,当然小程序是可以实现socket ...
- 数据展示Matplotlib
主要内容是Matplotlib库的基本使用和方法 1 Matplotlib库 1.1 Matplotlib的介绍 Python优秀的数据可视化第三方库 数据可视化就是将数据以特定的图形图像的方式展示出 ...