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 ...
随机推荐
- JAVA中的枚举使用总结
概念 在某些情况下,一个类的对象时有限且固定的,如季节类,它只有春夏秋冬4个对象这种实例有限且固定的类,在 Java 中被称为枚举类; 理解 类里面定义了固定数量的实例,类名如同命令空间 代码 pac ...
- 进入root权限操作
su:authentication failure的解决办法 $ su - rootPassword:su: Authentication failureSorry. 这时候输入 $ sudo pas ...
- ArcGIS API For Silverlight使用在线地图的多种方法总结
引自:http://www.cnblogs.com/meimao5211/p/3283969.html ArcGIS API For Silverlight使用在线地图的多种方法总结 本人也正在学习A ...
- openstack-mitaka版本DRV基础
一.基础知识 1.1 路由 1.1.1 策略路由 1.1.2 路由表 (使用 ip route 命令操作静态路由表) 1.1.3 路由分类之静态路由 1.1.4 路由分类之动态路由 1.1.5 ip ...
- shell编程实例1
1.vim hello.sh 2. #!bin/bash echo "hello world!" 3.chmod +x hello.sh 4.source hello.sh ls ...
- padding和margin的用法
在CSS中margin是指从自身边框到另一个容器边框之间的距离,就是容器外距离.在CSS中padding是指自身边框到自身内部另一个容器边框之间的距离,就是容器内距离. 一.padding 1.语法结 ...
- Android系统自带分享功能的实现(可同时分享文字和图片)
/** * 分享功能 * * @param context * 上下文 * @param activityTitle * Activity的名字 * @param msgTitle * 消息标题 ...
- 原生js面向对象写法
Mouse就是一个类,有自己的成员变量和成员方法,成员方法一定加上prototype,避免js原型的坑. var Mouse = function(id) { this.id = id; this.n ...
- 该文档举例说明了multimap的查找和删除元素的使用
该文档举例说明了multimap的查找和删除元素的使用. 其中,在使用迭代器遍历元素的时候,如果使用了删除迭代器的操作,那么需要小心迭代器失效的情况. /* 功能说明: multimap的查找和删除元 ...
- JAMstack 技术要点
1. 简要说明 Modern web development architecture based on client-side JavaScript, reusable APIs,and preb ...