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

思路:理解什么是拓扑排序就好了,简单题。需要注意的地方就是,因为这里要判断多个,每次判断都会改变入度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. LeetCode第[44]题(Java):Wildcard Matching

    题目:通配符匹配 难度:hard 题目内容: Given an input string (s) and a pattern (p), implement wildcard pattern match ...

  2. 条款19:定义class就相当于定义一个个的内置类型

    下面的条框应该是谨记的: 1. 新的type应该如何创建与销毁 2. 对象的初始化与赋值应该有什么样的区别 3. 新type的对象如果被pass-by-value,有什么影响? 4. 什么事新type ...

  3. 如何切换到自定义的Activity

    一. 新建一个空的工程,并添加一个按钮 二.新建一个布局文件,命名为my_aty, 并添加一个文本 三.新建一个类,命名为MyAty,并重写onCreate函数 public void onCreat ...

  4. JQuery动态隐藏和显示DIV

    <head> <script language="javascript"> function HideWeekMonth() { $("#tt1& ...

  5. SQL-left(right,inner) join

    left join(左联接) :返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) :返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) ...

  6. Ruby on Rails入门——macOS 下搭建Ruby Rails Web开发环境

    这里只介绍具体的过程及遇到的问题和解决方案,有关概念性的知识请参考另一篇:Ruby Rails入门--windows下搭建Ruby Rails Web开发环境 macOS (我的版本是:10.12.3 ...

  7. PhotoPicker 从头到脚

    1. 简介 PhotoPicker, 是一款开源的图片选择器.效果上和微信相似. 2. 使用方法 2.1 添加依赖 dependencies { compile 'me.iwf.photopicker ...

  8. WPS烦人问题

    [原]彻底解决WPS弹出热点广告.WPS购物图标的办法 搜索wpsnotify.exe,删除并新建同名文件. 搜索updateself.exe,删除并新建同名文件. 关闭我的WPS,搜索khomepa ...

  9. ubuntu 设置plank开机自启之后关机键失效变为注销键

    之前因为猎奇心,给我的ubuntu系统换了一个macUbuntu的桌面,但是之前用的dock是docky,昨日闲来无聊换成了plank,设置成然后就发现我的系统关不了机了,只能通过指令关机. 百度之后 ...

  10. [转载] C++中this指针的用法详解

    摘自:http://blog.chinaunix.net/uid-21411227-id-1826942.html 1. this指针的用处: 一个对象的this指针并不是对象本身的一部分,不会影响s ...