codevs 2833 奇怪的梦境 题解报告
来源:互联网 发布:美国人网购用什么软件 编辑:程序博客网 时间:2024/05/22 03:01
噫。。
题目描述 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
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<stack>#include<cstdlib>#include<string>#include<bitset>#include<iomanip>#include<deque>#define INF 1000000000#define fi first#define se second#define N 100005#define P 1000000007#define debug(x) cerr<<#x<<"="<<x<<endl#define MP(x,y) make_pair(x,y)using namespace std;int n,p,m,h[100001];int rd[100010];stack<int>s;struct zqm{ int v,next;}q[200001];void add(int a,int b){ p++; q[p].v=b; q[p].next=h[a]; h[a]=p;}inline int get_num(){int num = 0;char c;bool flag = false;while ((c = getchar()) == ' ' || c == '\n' || c == '\r');if (c == '-') flag = true;else num = c - '0';while (isdigit(c = getchar()))num = num * 10 + c - '0';return (flag ? -1 : 1) * num;}void topusort(){ for(int i=1;i<=n;i++) { if(rd[i]==0) { s.push(i); } } while(!s.empty()) { int t=s.top(); s.pop(); p=h[t]; while(p) { int k=q[p].v; rd[k]--; if(rd[k]==0) { s.push(k); } p=q[p].next; } }}int main(){ cin>>n>>m; for(int i=1;i<=m;i++) { int q,w; cin>>q>>w; add(q,w); rd[w]++; } topusort(); bool vv=0; int cnt=0; for(int i=1;i<=n;i++) { if(rd[i]) { vv=1; cnt++; } }if(vv) { cout<<"T_T\n"; cout<<cnt; }else cout<<"o(∩_∩)o";}
0 0
- codevs 2833 奇怪的梦境 题解报告
- CodeVs 2833 奇怪的梦境
- 【CODEVS】2833 奇怪的梦境
- Codevs 2833 奇怪的梦境
- 【codevs 2833】奇怪的梦境
- 【codevs 2833】奇怪的梦境
- Codevs 2833 奇怪的梦境
- codevs 2833 奇怪的梦境 拓扑排序
- 2833 奇怪的梦境 【解题报告】
- codevs 2833 奇怪的梦境(拓扑排序)
- codevs 2833 奇怪的梦境(拓扑排序)
- 2833 奇怪的梦境
- 2833 奇怪的梦境
- 2833 奇怪的梦境
- codevs奇怪的梦境(拓扑排序)
- 【基础练习】【拓扑排序】codevs2833 奇怪的梦境题解
- [codevs2833] 奇怪的梦境
- 奇怪的梦境
- OkHttpUtils用法以及jar包
- 第十周项目3(1)实现基本功能
- js实现页面左右上下拖拽
- 集合(3-栈 Stack)
- 谈一谈当下的全栈式工程师
- codevs 2833 奇怪的梦境 题解报告
- python 函数 之 self
- SQL Server Database在C#编程下遇到的问题:“provider:SQL Network Interfaces,error:26-定位指定的服务器/实例时出错”的解决办法
- HTML中的音频视频格式
- C语言中动态分配数组
- 编程练习题
- 【图像处理】图像特征提取:图像的矩特征
- 巴蜀 2311【练习试题】宫廷守卫
- leetcode 413. Arithmetic Slices [medium]