codevs2833 奇怪的梦境
Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很多按钮,还有一个屏幕,上面显示了一些信息。屏幕上说,要将所有按钮都按下才能出去,而又给出了一些信息,说明了某个按钮只能在另一个按钮按下之后才能按下,而没有被提及的按钮则可以在任何时候按下。可是Aiden发现屏幕上所给信息似乎有矛盾,请你来帮忙判断。
第一行,两个数N,M,表示有编号为1...N这N个按钮,屏幕上有M条信息。
接下来的M行,每行两个数ai,bi,表示bi按钮要在ai之后按下。所给信息可能有重复,保证ai≠bi。
若按钮能全部按下,则输出“o(∩_∩)o”。
若不能,第一行输出“T_T”,第二行输出因信息有矛盾而无法确认按下顺序的按钮的个数。输出不包括引号。
3 3
1 2
2 3
3 2
T_T
2
对于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 奇怪的梦境的更多相关文章
- codevs2833 奇怪的梦境 x
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中 ...
- 奇怪的梦境(codevs 2833)
题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很多按钮,还有一个屏幕,上面显示了一些信息.屏幕上说,要将所有按钮都按下才能出去,而又给出了一些信息,说明 ...
- Codevs 2833 奇怪的梦境
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很多按钮,还 ...
- 2833 奇怪的梦境 未AC
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小 ...
- CODEVS——T 2833 奇怪的梦境
http://codevs.cn/problem/2833/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descr ...
- 【CODEVS】2833 奇怪的梦境
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很 ...
- [wikioi]奇怪的梦境
http://wikioi.com/problem/2833/ 拓扑排序,居然1A,哈哈. #include <cstdio> #include <iostream> #inc ...
- 【拓扑排序】CODEVS 2833 奇怪的梦境
拓扑排序模板. #include<cstdio> #include<vector> #include<stack> using namespace std; #de ...
- 1、Codevs 必做:2833、1002、1003、2627、2599
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困 ...
随机推荐
- LeetCode 1002. Find Common Characters (查找常用字符)
题目标签:Array, Hash Table 题目给了我们一个string array A,让我们找到common characters. 建立一个26 size 的int common array, ...
- LeetCode 720. Longest Word in Dictionary (字典里最长的单词)
Given a list of strings words representing an English Dictionary, find the longest word in words tha ...
- leetCode 54.Spiral Matrix(螺旋矩阵) 解题思路和方法
Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matri ...
- _io.TextIOWrapper
''' SELECT * FROM Info_Roles WHERE Flag=1 LIMIT 2; select top y * from 表 where 主键 not in(select top ...
- yum install -y dos2unix
yum install -y dos2unix linux 怎么把^M去掉 - CSDN博客 http://blog.csdn.net/humanof/article/details/53044217 ...
- S6十大特性
http://www.alloyteam.com/2016/03/es6-front-end-developers-will-have-to-know-the-top-ten-properties/
- oc79--数组的内存管理
// // main.m // 集合(数组)对象的内存管理(MRC中) // #import <Foundation/Foundation.h> #import "Person. ...
- SPOJ XMAX - XOR Maximization
XMAX - XOR Maximization Given a set of integers S = { a1, a2, a3, ... a|S| }, we define a function X ...
- JavaScript Patterns 2.3 For loops
HTMLCollections are objects returned by DOM methods such as: • document.getElementsByName() • docume ...
- 【POJ 3349】 Snowflake Snow Snowflakes
[题目链接] http://poj.org/problem?id=3349 [算法] 哈希 若两片雪花相同,则它们六个角上的和一定相同,不妨令 H(A) = sigma(Ai) % P ,每次只要到哈 ...