博客
关于我
HDU 1285 确定比赛名次【拓扑排序】链式向前星+优先队列
阅读量:369 次
发布时间:2019-03-04

本文共 1609 字,大约阅读时间需要 5 分钟。

?????????????????????????????????????????????????????????????????????????????????????????

????

  • ????: ?????????????????????????????????????????P1?P2?????????????????????????

  • ????: ????????????????????????????????Kahn???????????????????????DAG??

  • ????: ?Kahn??????????????????0????????????????????????????????????

  • ????:

    • ???????????0?
    • ?????????????????????
    • ????0??????????
    • ????????????????????????
    • ?????????????????
  • ????

    #include 
    #include
    #include
    #include
    #include
    using namespace std;int main() { int n, m; while (true) { cin >> n >> m; if (m == 0) break; vector
    in(n + 1, 0); vector
    head(n + 1); vector
    > adj(n + 1); int cnt = 0; for (int i = 1; i <= m; ++i) { int p1, p2; cin >> p1 >> p2; adj[p1].push_back(p2); in[p2]++; } // Initialize the priority queue priority_queue
    , greater
    > q; for (int i = 1; i <= n; ++i) { if (in[i] == 0) q.push(i); } vector
    ans; while (!q.empty()) { int u = q.top(); q.pop(); ans.push_back(u); for (int v : adj[u]) { in[v]--; if (in[v] == 0) q.push(v); } } // Output the result if (ans.size() != n) { // This should not happen as per the problem statement cout << "Error" << endl; } else { for (int i = 0; i < ans.size(); ++i) { if (i > 0) cout << " "; cout << ans[i]; } } } return 0;}

    ????

  • ????: ????????n???????m????????????????????????

  • ???????: ????????????0?????????????????????

  • ????: ??Kahn???????????????????????????????0?????????

  • ????: ????????????????????

  • ???????????????????????????????????????????

    转载地址:http://qlyg.baihongyu.com/

    你可能感兴趣的文章
    mysql中对于数据库的基本操作
    查看>>
    Mysql中常用函数的使用示例
    查看>>
    MySql中怎样使用case-when实现判断查询结果返回
    查看>>
    Mysql中怎样使用update更新某列的数据减去指定值
    查看>>
    Mysql中怎样设置指定ip远程访问连接
    查看>>
    mysql中数据表的基本操作很难嘛,由这个实验来带你从头走一遍
    查看>>
    Mysql中文乱码问题完美解决方案
    查看>>
    mysql中的 +号 和 CONCAT(str1,str2,...)
    查看>>
    Mysql中的 IFNULL 函数的详解
    查看>>
    mysql中的collate关键字是什么意思?
    查看>>
    MySql中的concat()相关函数
    查看>>
    mysql中的concat函数,concat_ws函数,concat_group函数之间的区别
    查看>>
    MySQL中的count函数
    查看>>
    MySQL中的DB、DBMS、SQL
    查看>>
    MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
    查看>>
    MySQL中的GROUP_CONCAT()函数详解与实战应用
    查看>>
    MySQL中的IO问题分析与优化
    查看>>
    MySQL中的ON DUPLICATE KEY UPDATE详解与应用
    查看>>
    mysql中的rbs,SharePoint RBS:即使启用了RBS,内容数据库也在不断增长
    查看>>
    mysql中的undo log、redo log 、binlog大致概要
    查看>>