codevs 2833 奇怪的梦境 题解报告
2016-11-07 16:11
405 查看
噫。。
题目描述 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"; }
相关文章推荐
- 奇怪的梦境(codevs 2833)
- Codevs 2833 奇怪的梦境
- CODEVS——T 2833 奇怪的梦境
- codevs 2833 奇怪的梦境(拓扑排序)
- codevs 2833 奇怪的梦境(拓扑排序)
- Codevs 2833 奇怪的梦境
- 【拓扑排序】CODEVS 2833 奇怪的梦境
- codevs 2833 奇怪的梦境
- codevs 1036 商务旅行 题解报告
- codevs 2488 绿豆蛙的归宿 题解报告
- 2833 奇怪的梦境 【解题报告】
- codevs 1507 酒厂选址 题解报告
- codevs 1060 搞笑世界杯 题解报告
- codevs 3301 Square words 题解报告
- codevs 1058 合唱队形 题解报告
- codevs 1065 01字符串 题解报告
- codevs 1009 产生数 题解报告
- codevs 1961 躲避大龙 题解报告
- codevs 1019 集合论与图论 题解报告
- codevs 1045 回文数 题解报告