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 ...
随机推荐
- mysql create database and user 新建数据库并为其创建专用账号
DROP DATABASE `wordpress`;------------------------------------------------------------------ CREATE ...
- scala LocalDateTime String 转换
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");LocalDateTime ti ...
- MFC--串口编程---WIN API的方式将串扣操作封装在线程类中
串口采集数据 本文档介绍的是如何获取串口原始数据并将原始数据解析成可处理或可展示的数据. 一.串口采集有很多方式: 1).MFC有一个专门的控件,直接编程采集,一个控件只能采集一个串口,而且串口名字比 ...
- Linux 任务控制(bg job fg nohup &) (转)
常用命令 & 将指令丢到后台中去执行[ctrl]+z 將前台任务丟到后台中暂停jobs 查看后台的工作状态fg %jobnumber 将后台的任务拿到前台来处理bg %jobnumber 将任 ...
- Linux:配置Linux网络和克隆虚拟机并更改配置
Linux学习笔记1:配置Linux网络和克隆虚拟机并更改配置 一.配置Linux网络 在安装Linux的时候,一定要保证你的物理网络的IP是手动设置的,要不然会在Linux设置IP连通网络的时候 ...
- LeetCode OJ:Valid Parentheses(有效括号)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- L138
Research indicates that lifestyles are changing fast.The essay isn't even remotely relevant to the t ...
- TF随笔-4
>>> import tensorflow as tf>>> a=tf.constant([[1,2],[3,4]])>>> b=tf.const ...
- 在ubuntu14.4里编译UBOOT出错
出错信息如下: OBJCOPY examples/standalone/hello_world.bin LDS u-boot.lds LD u-boot./scripts/dtc ...
- EasyDSS流媒体服务器出现no compatible source was found for this media问题的解决
在EasyDSS流媒体服务器的客户反馈中,我们遇到这样一个现象,在chrome中经常会出现RTMP/HLS流无法播放的问题: 这个问题复现的几率比较低,因为chrome禁止了flash的加载,这也从另 ...