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

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

    1. 应该可以将所有的 jni需要的函数都放在一个 dll中(Windows下),然后 多个java项目就只要调用一个dll了. 可以测试一下 2.

  2. InflateException:Bin file line #19:Error inflating class MyTextView

    InflateException:Bin file line #19:Error inflating class MyTextView 一.错误简介 为了实现TextView的跑马灯效果,我自己写了一 ...

  3. Java泛型中的标记符含义

    Java泛型中的标记符含义:  E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Number ...

  4. oracle:与mysql相似得find_set_in函数用法

    Oracle中实现find_in_set CREATEORREPLACEFUNCTION FIND_IN_SET(piv_str1 varchar2, piv_str2 varchar2, p_sep ...

  5. Cassandra二级索引原理——新创建了一张表格,同时将原始表格之中的索引字段作为新索引表的Primary Key,并且存储的值为原始数据的Primary Key,然后再通过pk一级索引找到真正的值

    1.什么是二级索引? 我们前面已经介绍过Cassandra之中有各种Key,比如Primary Key, Cluster Key 等等.如果您对这部分概念并不熟悉,可以参考之前的文章: [Cassan ...

  6. MySQL-5.7复制功能的默认设置改进

    1. 默认开启简化的GTID 恢复 Binlog_gtid_simple_recovery=TURE(默认值)      这个参数控制了当mysql启动或重启时,mysql在搜寻GTIDs时是如何迭代 ...

  7. LeetCode OJ:Best Time to Buy and Sell Stock II(股票买入卖出最佳实际II)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  8. form表单的提交地址一定要是完整的绝对地址

    <form action="<%=path%>/servlet/DologinServlet" =<form action="<%=requ ...

  9. 【tensorflow:Google】二、Tensorflow环境搭建

    2.1 Tensorflow 主要依赖包 2.1.1 Protocol Buffer 结构化数据序列化的过程,另外的工具:XML, JSON, 区别:二进制(不可读):先定义数据格式,还原的时候将需要 ...

  10. 理解字符串 Boyer-Moore 算法

    作者: 阮一峰 上一篇介绍了 kmp算法 但是,它并不是效率最高的算法,实际采用并不多. 各种文本编辑器的"查找"功能(Ctrl+F),大多采用Boyer-Moore算法. Boy ...