http://wikioi.com/problem/2833/

拓扑排序,居然1A,哈哈。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
#define MAX(a, b) a>b?a:b
#define LEN 105
using namespace std; int main()
{
int n, m;
scanf("%d%d", &n, &m);
vector<vector<int> > graph(n+1);
vector<int> indegree(n+1);
vector<bool> visit(n+1);
int ans = n;
while (m--) {
int x = 0;
int y = 0;
scanf("%d%d", &x, &y);
indegree[y]++;
graph[x].push_back(y);
}
queue<int> que;
for (int i = 1; i <= n; i++) {
if (indegree[i] == 0) {
que.push(i);
visit[i] = true;
ans--;
}
}
while (!que.empty()) {
int node = que.front();
que.pop();
for (int i = 0; i < graph[node].size(); i++) {
if (!visit[graph[node][i]]) {
indegree[graph[node][i]]--;
if (indegree[graph[node][i]] == 0) {
que.push(graph[node][i]);
visit[graph[node][i]] = true;
ans--;
}
}
}
}
if (ans == 0) puts("o(∩_∩)o\n");
else {
puts("T_T\n");
printf("%d\n", ans);
}
return 0;
}

  

[wikioi]奇怪的梦境的更多相关文章

  1. 奇怪的梦境(codevs 2833)

    题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很多按钮,还有一个屏幕,上面显示了一些信息.屏幕上说,要将所有按钮都按下才能出去,而又给出了一些信息,说明 ...

  2. Codevs 2833 奇怪的梦境

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold     题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很多按钮,还 ...

  3. 2833 奇怪的梦境 未AC

    2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold         题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小 ...

  4. codevs2833 奇怪的梦境

    2833 奇怪的梦境  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description Aiden陷入了一个奇怪的梦境:他被困 ...

  5. CODEVS——T 2833 奇怪的梦境

    http://codevs.cn/problem/2833/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Descr ...

  6. codevs2833 奇怪的梦境 x

    2833 奇怪的梦境  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中 ...

  7. 【CODEVS】2833 奇怪的梦境

    2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很 ...

  8. 【拓扑排序】CODEVS 2833 奇怪的梦境

    拓扑排序模板. #include<cstdio> #include<vector> #include<stack> using namespace std; #de ...

  9. 1、Codevs 必做:2833、1002、1003、2627、2599

    2833 奇怪的梦境  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description Aiden陷入了一个奇怪的梦境:他被困 ...

随机推荐

  1. 自定义标签 tld

    初学者可能在不借助IDE工具的情况下 编写自定义标签库 tld  程序可能遇到找不到class 的错误,下面讲解一下如何解决该问题 步骤一:新建一个自定义标签类 HelloWorldTag,该类放到s ...

  2. Servlet & JSP - Decorating Requests and Responses

    Servlet API 提供了四个包装类:ServletRequestWrapper.ServletResponseWrapper.HttpServletRequestWrapper.HttpServ ...

  3. windows server 2008镜像重启后密码变为默认密码的问题的解决方案

    1. cmd中执行regedit,打开注册表: 修改HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cloudbase Solusions\Cloudbase-Init ...

  4. IOS 学习笔记 2015-03-20 O之 nil,Nil,NULL,NSNull

    1.oc最好 用nil   [ nil  任意方法],不会崩溃 nil 是一个对象值.NULL是一个通用指针(泛型指针). 2. NSNULL,NULL和nil在本质上应该是一样的,NULL和nil其 ...

  5. IQueryable接口与IEnumberable区别

    IEnumerable<T> 泛型类在调用自己的SKip 和 Take 等扩展方法之前数据就已经加载在本地内存里了,而IQueryable<T> 是将Skip ,take 这些 ...

  6. Python中 if __name__ == '__main__': 详解

    一个python文件就可以看作是一个python的模块,这个python模块(.py文件)有两种使用方式:直接运行和作为模块被其他模块调用. __name__:每一个模块都有一个内置属性__name_ ...

  7. Linux内核设计与实现 读书笔记

    第三章 进程管理 1. fork系统调用从内核返回两次: 一次返回到子进程,一次返回到父进程 2. task_struct结构是用slab分配器分配的,2.6以前的是放在内核栈的栈底的:所有进程的ta ...

  8. jquery 插件的编写

    /** * 插件的学习 * 原文地址:http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html#home */ ;(function($, ...

  9. 移动端reset.css

    * { margin:; padding:; } article, aside, details, figcaption, figure, footer, header, hgroup, main, ...

  10. [Caffe] ubuntu14.04下使用OpenBLAS加速Caffe

    一.apt安装 sudo apt-get install libopenblas-dev 二.手动从source安装 1. 下载OpenBLAS并编译 git clone https://github ...