题意:判断序列是否为拓扑序列。

思路:理解什么是拓扑排序就好了,简单题。需要注意的地方就是,因为这里要判断多个,每次判断都会改变入度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的更多相关文章

  1. PAT 1146 Topological Order[难]

    1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which o ...

  2. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  3. PAT 甲级 1146 Topological Order

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343043829760 This is a problem give ...

  4. [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 ...

  5. PAT 1146 Topological Order

    This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...

  6. 1146. Topological Order (25)

    This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...

  7. 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 ...

  8. A1146. Topological Order

    This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...

  9. 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 ...

随机推荐

  1. 使用SpringMVC时报错HTTP Status 405 - Request method 'GET' not supported

    GET方法不支持.我出错的原因在于,在JSP中我希望超链接a以post方式提交,但是这里写js代码时出错. <script type="text/javascript"> ...

  2. 利用JS获取地址栏的中文参数

    地址栏中为:localhost:22865/ZYHSYY.aspx?BQH=305&DoctorName=张三&DoctorId=100我想利用JS获取到“张三”,请问该如何写js?目 ...

  3. 在UIElement外面多套一层布局面板(Grid、StackPanel)的意义

    在一个UIElement或多个UIElement外面套上一层布局面板(Grid.StackPanel),可以起到统一管理作用(非重点关注):另外,更重要的是:可以起到扩大UIElement操作有效范围 ...

  4. mysql数据库(二):查询(SELECT)

    一. 数据库查询—查询(SELECT) 单表查询 多表联合查询 二. 查询—单表查询 查询特定字段: select <字段1,字段2,...> from <表名>; 示例:查询 ...

  5. 百度之星2017初赛A-1006-度度熊的01世界

    度度熊的01世界 Accepts: 967 Submissions: 3064 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...

  6. Kestrel 服务器部署多站点问题 (nginx 反向代理)

    Kestrel 作为微软的跨平台 web 服务器,有些地方用的好不是很熟. 作为一款嵌套到 dll 中的进程级 web 服务器,在同一台服务器上部署多站点确实还存在一点问题. 今天采用 nginx 做 ...

  7. LeetCode OJ:First Missing Positive (第一个丢失的正数)

    在leetCode上做的第一个难度是hard的题,题目如下: Given an unsorted integer array, find the first missing positive inte ...

  8. canvas操作图片,进行面板画图,旋转等

    HTML5 <canvas> 标签用于绘制图像(通过脚本,通常是 JavaScript). 不过,<canvas> 元素本身并没有绘制能力(它仅仅是图形的容器) - 您必须使用 ...

  9. 转一篇pgpool配置

    转一篇pgpool配置 http://dz.sdut.edu.cn/blog/subaochen/2013/08/postgresql-9-1的failover配置及其管理/ 环境介绍 在两台虚拟机上 ...

  10. Juint 单元测试(1)

    Junit 是一个基于Java语言的回归单元测试框架.是白盒测试的一种技术,记住这些就可以了. 为项目添加Junit 1 右键项目名称选择“Properties”,在弹出的窗体中选择“Java Bui ...