2833 奇怪的梦境

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
 
 
 
题目描述 Description

Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很多按钮,还有一个屏幕,上面显示了一些信息。屏幕上说,要将所有按钮都按下才能出去,而又给出了一些信息,说明了某个按钮只能在另一个按钮按下之后才能按下,而没有被提及的按钮则可以在任何时候按下。可是Aiden发现屏幕上所给信息似乎有矛盾,请你来帮忙判断。

输入描述 Input Description

第一行,两个数N,M,表示有编号为1...N这N个按钮,屏幕上有M条信息。

接下来的M行,每行两个数ai,bi,表示bi按钮要在ai之后按下。所给信息可能有重复,保证ai≠bi。

输出描述 Output Description

若按钮能全部按下,则输出“o(∩_∩)o”。

若不能,第一行输出“T_T”,第二行输出因信息有矛盾而无法确认按下顺序的按钮的个数。输出不包括引号。

样例输入 Sample Input

3 3

1 2

2 3

3 2

样例输出 Sample Output

T_T

2

数据范围及提示 Data Size & Hint

对于30%的数据,保证0<N≤100。

对于50%的数据,保证0<N≤2000。

对于70%的数据,保证0<N≤5000。

对于100%的数据,保证0<N≤10000,0<M≤2.5N。

分类标签 Tags 点此展开

 
 

简单拓扑排序,判断环的存在与否,以及在环中的个数,在环中的点一定不会入队列

#include<bits/stdc++.h>

#define N 10101001
using namespace std; int n,m,head[N],tot,rd[N];
struct node{
int to,next;
}e[N]; void add(int u,int v){
e[++tot].to=v,e[tot].next=head[u],head[u]=tot;
} queue<int>Q;
int cnt;
int topo(){
for(int i=;i<=n;i++) if(!rd[i]) Q.push(i);
while(!Q.empty()){
int u=Q.front();Q.pop();++cnt;
for(int i=head[u];i;i=e[i].next){
int v=e[i].to;
rd[v]--;
if(!rd[v]) Q.push(v);
}
}return cnt;
} int main()
{
scanf("%d%d",&n,&m);
for(int a,b,i=;i<=m;i++){
scanf("%d%d",&a,&b);
add(a,b);rd[b]++;
}
if(topo()!=n){
printf("T_T\n%d",n-cnt);
}else printf("o(∩_∩)o\n");
return ;
}

codevs2833 奇怪的梦境的更多相关文章

  1. codevs2833 奇怪的梦境 x

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

  2. 奇怪的梦境(codevs 2833)

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

  3. Codevs 2833 奇怪的梦境

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

  4. 2833 奇怪的梦境 未AC

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

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

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

  6. 【CODEVS】2833 奇怪的梦境

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

  7. [wikioi]奇怪的梦境

    http://wikioi.com/problem/2833/ 拓扑排序,居然1A,哈哈. #include <cstdio> #include <iostream> #inc ...

  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. swift 2.0 语法 字典

    //: Playground - noun: a place where people can play import UIKit /*: 字典 * 和OC的区别 * 1. {} 替换为 [] * 2 ...

  2. HDUOJ--2121--Ice_cream’s world II【朱刘算法】不定根最小树形图

    链接:http://acm.hdu.edu.cn/showproblem.php? pid=2121 题意:n个顶点,m条边,求从某一点起建立有向图最小生成树而且花费最小.输出最小花费和根节点下标. ...

  3. js 四种调用方式 Method Invocation Pattern

    4.3. Invocation Invoking a function suspends the execution of the current function, passing control ...

  4. Window attributes属性详解

    以下属性以Dialog为例来讲解: <item name="windowBackground"> 窗体的背景 </item><item name=&q ...

  5. influxdb入门——和mongodb一样可以动态增加字段

    ./influxd [--config yourconfigfile 2> /dev/null]  之所以重定向 因为默认log是stderr 再启动客户端./influx > CREAT ...

  6. bzoj1977 [BeiJing2010组队]次小生成树 Tree——严格次小生成树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1977 因为严格,所以要记录到 LCA 的一个次小值: 很快写好,然后改掉一堆错误后终于过了样 ...

  7. npm 与 package.json 快速入门教程

    npm 与 package.json 快速入门教程 2017年08月02日 19:16:20 阅读数:33887 npm 是前端开发广泛使用的包管理工具,之前使用 Weex 时看了阮一峰前辈的文章了解 ...

  8. codevs1163访问艺术馆(树形dp)

    1163 访问艺术馆  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master   题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备, ...

  9. PropertyInfo 类

    [AttributeUsage(AttributeTargets.Property)] //Models 特性        public class CanWriteAttribute : Attr ...

  10. [Swift通天遁地]八、媒体与动画-(14)使用TextKit快速实现文章的分栏效果

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...