您的位置:首页 > 其它

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";
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息