博客
关于我
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/

    你可能感兴趣的文章
    Netty 高性能架构设计
    查看>>
    Netty+Protostuff实现单机压测秒级接收35万个对象实践经验分享
    查看>>
    Netty+SpringBoot+FastDFS+Html5实现聊天App详解(一)
    查看>>
    netty--helloword程序
    查看>>
    netty2---服务端和客户端
    查看>>
    【Flink】Flink 2023 Flink易用性和稳定性在Shopee的优化-视频笔记
    查看>>
    Netty5.x 和3.x、4.x的区别及注意事项(官方翻译)
    查看>>
    netty——bytebuf的创建、内存分配与池化、组成、扩容规则、写入读取、内存回收、零拷贝
    查看>>
    netty——Channl的常用方法、ChannelFuture、CloseFuture
    查看>>
    netty——EventLoop概念、处理普通任务定时任务、处理io事件、EventLoopGroup
    查看>>
    netty——Future和Promise的使用 线程间的通信
    查看>>
    netty——Handler和pipeline
    查看>>
    Vue输出HTML
    查看>>
    netty——黏包半包的解决方案、滑动窗口的概念
    查看>>
    Netty中Http客户端、服务端的编解码器
    查看>>
    Netty中使用WebSocket实现服务端与客户端的长连接通信发送消息
    查看>>
    Netty中实现多客户端连接与通信-以实现聊天室群聊功能为例(附代码下载)
    查看>>
    Netty中的组件是怎么交互的?
    查看>>
    Netty中集成Protobuf实现Java对象数据传递
    查看>>
    netty之 定长数据流处理数据粘包问题
    查看>>