codevs 2833 奇怪的梦境 题解报告

24 篇文章 0 订阅
8 篇文章 0 订阅

雷姆镇楼

噫。。

题目描述 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值