codevs 2833 奇怪的梦境 拓扑排序
来源:互联网 发布:latex for mac下载 编辑:程序博客网 时间:2024/05/22 12:49
传送门:codevs2833奇怪的梦境
题目大意:额···中文题···
解题思路:拓扑排序, 就是遍历所有数的出度, 找出有没有环。 代码思路:遍历所有数的出度,将遍历到的数入度减一, 所有数的入度均为0时就可以将所有数都按下。
AC代码:
#include <iostream>#include <cstdio>#include <vector>#include <queue>using namespace std;vector<int> to[10005];queue<int> que;int rd[10005];void Build(int a, int b){to[a].push_back(b);rd[b]++;}int toposort(int n){int cnt = 0;for(int i=1; i<=n; i++)if(!rd[i]){cnt++;que.push(i);}while(!que.empty()){int f = que.front(); que.pop();for(int i=0; i<to[f].size(); i++){int v = to[f][i];rd[v]--;if(!rd[v]){que.push(v);cnt++;}}}return cnt;}int main(){int n, m;scanf("%d%d", &n, &m);int a, b;for(int i=0; i<m; i++){scanf("%d%d", &a, &b);Build(a, b);}int sum = toposort(n);if(sum >= n) printf("o(∩_∩)o\n");else printf("T_T\n%d\n", n - sum);return 0;}
阅读全文
0 0
- codevs 2833 奇怪的梦境 拓扑排序
- codevs奇怪的梦境(拓扑排序)
- codevs 2833 奇怪的梦境(拓扑排序)
- codevs 2833 奇怪的梦境(拓扑排序)
- CodeVs 2833 奇怪的梦境
- 【CODEVS】2833 奇怪的梦境
- Codevs 2833 奇怪的梦境
- 【codevs 2833】奇怪的梦境
- 【codevs 2833】奇怪的梦境
- Codevs 2833 奇怪的梦境
- codevs2833 2833 奇怪的梦境(拓扑排序)
- 【CS 2833】奇怪的梦境(拓扑排序top_sort)
- 【codevs2833】奇怪的梦境 拓扑排序
- codevs 2833 奇怪的梦境 题解报告
- 【基础练习】【拓扑排序】codevs2833 奇怪的梦境题解
- 2833 奇怪的梦境
- 2833 奇怪的梦境
- 2833 奇怪的梦境
- LightOJ 1141 Number Transformation
- 创建一个Node.js应用
- ZOJ 3958Cooking Competition
- phalcon框架中的聚合
- 剑指offer题63
- codevs 2833 奇怪的梦境 拓扑排序
- okhttp中的线程池及源码分析
- Spring Cloud微服务(6)之spring cloud config分布式配置中心
- Maven战笔记
- 七月英语总结——不离开便不会陌生
- 1165: 实数的小数部分(指针专题)
- NetBeans生成JAR
- 导出Excel工具类
- Java中Set转List 和 TreeMap中实现自定义类作为key值