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

思路:理解什么是拓扑排序就好了,简单题。需要注意的地方就是,因为这里要判断多个,每次判断都会改变入度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. MyBatis使用自定义TypeHandler转换类型

    MyBatis虽然有很好的SQL执行性能,但毕竟不是完整的ORM框架,不同的数据库之间SQL执行还是有差异. 笔者最近在升级 Oracle 驱动至 ojdbc 7 ,就发现了处理DATE类型存在问题. ...

  2. 本地测试ajax遇到的跨域问题

    浏览器console问题描述:Cross origin requests are only supported for protocol schemes: http, data, chrome, ch ...

  3. 使用maven时报错An error occurred while filtering resources

    解决办法:右键项目-->maven-->update project   .

  4. KMP算法--C#版

    static void BuildTable(string subString, ref int[] next) { if (string.IsNullOrWhiteSpace(subString)) ...

  5. python迭代器与生成器(二)

      一.什么是迭代? 迭代通俗的讲就是一个遍历重复的过程. 维基百科中 迭代(Iteration) 的一个通用概念是:重复某个过程的行为,这个过程中的每次重复称为一次迭代.具体对应到Python编程中 ...

  6. Android读取asserts和raw文件夹下的文件

    Android读取asserts和raw文件夹下的文件 经常需要用到读取“/res/raw”和"/asserts"文件夹下的文件,索性写成工具类方便以后使用. 一.raw文件夹下的 ...

  7. MySQL install and setting

    Tomorrow is the deadline of DATABASE, I am very nervous because of my project. Today is first day th ...

  8. Gradle配置IDEA正常识别JPA Metamodel Generator动态生成的代码

    我们在使用JPA动态查询构建查询条件时,为了实现安全的类型检查,常常需要引用Hibernate JPA Metamodel Generator自动为我们生成静态元模型类. 而这些类由于编译时由Hibe ...

  9. sublime 非常好用的注释工具

    Sublime在进行前端开发时非常棒,当然也少不了众多的插件支持,DocBlocker是在Sublime平台上开发一款自动补全代码插件,支持JavaScript (including ES6), PH ...

  10. Windows下运行Hadoop

    Windows下运行Hadoop,通常有两种方式:一种是用VM方式安装一个Linux操作系统,这样基本可以实现全Linux环境的Hadoop运行:另一种是通过Cygwin模拟Linux环境.后者的好处 ...