CODEVS——T 2833 奇怪的梦境
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。
#include <algorithm>
#include <cstdio> using namespace std; const int N(+);
const int M(+);
int head[N],sumedge;
struct Edge
{
int v,next;
Edge(int v=,int next=):v(v),next(next){}
}edge[M];
inline void ins(int u,int v)
{
edge[++sumedge]=Edge(v,head[u]);
head[u]=sumedge;
} int tim,dfn[N],low[N];
int top,Stack[N],instack[N];
int sumcol,col[N],point[N];
void DFS(int now)
{
low[now]=dfn[now]=++tim;
Stack[++top]=now;instack[now]=;
for(int v,i=head[now];i;i=edge[i].next)
{
v=edge[i].v;
if(!dfn[v]) DFS(v),low[now]=min(low[now],low[v]);
else if(instack[v]) low[now]=min(low[now],dfn[v]);
}
if(low[now]==dfn[now])
{
col[now]=++sumcol;
point[sumcol]++;
for(;Stack[top]!=now;top--)
{
col[Stack[top]]=sumcol;
point[sumcol]++;
instack[Stack[top]]=;
}
top--; instack[now]=;
}
} int main()
{
int n,m,ans=;
scanf("%d%d",&n,&m);
for(int u,v;m--;)
scanf("%d%d",&u,&v),ins(u,v);
DFS();
for(int i=;i<=n;i++) if(!dfn[i])
for(int i=;i<=sumcol;i++)
if(point[i]>) ans+=point[i];
if(ans) printf("T_T\n%d",ans);
else printf("o(∩_∩)o");
return ;
}
只A掉样例的Tarjan、
拓扑排序求环内点数
#include <algorithm>
#include <cstdio>
#include <queue> using namespace std; const int N(+);
const int M(+); queue<int>que;
int rd[N],head[N],sumedge;
struct Edge
{
int v,next;
Edge(int v=,int next=):v(v),next(next){}
}edge[M];
inline void ins(int u,int v)
{
edge[++sumedge]=Edge(v,head[u]);
head[u]=sumedge;
} int main()
{
int n,m;
scanf("%d%d",&n,&m);
int ans=n;
for(int u,v;m--;)
scanf("%d%d",&u,&v),ins(u,v),rd[v]++;
for(int i=;i<=n;i++)
if(!rd[i]) que.push(i);
for(int u,v;!que.empty();)
{
ans--;
u=que.front(); que.pop();
for(int i=head[u];i;i=edge[i].next)
{
v=edge[i].v;
if(--rd[v]==) que.push(v);
}
}
if(!ans) printf("o(∩_∩)o");
else printf("T_T\n%d",ans);
return ;
}
CODEVS——T 2833 奇怪的梦境的更多相关文章
- 【CODEVS】2833 奇怪的梦境
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很 ...
- 2833 奇怪的梦境 未AC
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小 ...
- Codevs 2833 奇怪的梦境
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很多按钮,还 ...
- 【拓扑排序】CODEVS 2833 奇怪的梦境
拓扑排序模板. #include<cstdio> #include<vector> #include<stack> using namespace std; #de ...
- codevs2833 奇怪的梦境
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困 ...
- codevs2833 奇怪的梦境 x
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中 ...
- 奇怪的梦境(codevs 2833)
题目描述 Description Aiden陷入了一个奇怪的梦境:他被困在一个小房子中,墙上有很多按钮,还有一个屏幕,上面显示了一些信息.屏幕上说,要将所有按钮都按下才能出去,而又给出了一些信息,说明 ...
- [wikioi]奇怪的梦境
http://wikioi.com/problem/2833/ 拓扑排序,居然1A,哈哈. #include <cstdio> #include <iostream> #inc ...
- 【CodeVS】 p1696 奇怪的函数
题目描述 Description 自从得到上次的教训后,John的上课态度认真多了,也变得更爱动脑筋了.今天他又学习了一个新的知识:关于 xk 的位数. 如果x大于0小于l,那么位数=1+小数部分×k ...
随机推荐
- Linux 安装软件的几种方式
目录 几种安装方式 源代码编译安装 借助软件包管理器安装 二进制格式安装 总结 参考 几种安装方式 源代码编译安装 源代码包的安装一般为下载软件源代码,然后编译安装.常见的 C 程序软件的安装步骤是 ...
- 1028C:Rectangles
You are given n rectangles on a plane with coordinates of their bottom left and upper right points. ...
- swift语言点评二十-扩展
结论:扩展无法修改原来的数据结构. Extensions can add new functionality to a type, but they cannot override existing ...
- SpringCloud学习笔记(3)----Spring Cloud Netflix之深入理解Eureka
1. Eureka服务端的启动过程 1.1 入口类EurekaServerInitializerConfiguration类, public void start() { (new Thread(n ...
- NOIp2018模拟赛四十五~??
欠的太多,咕了咕了 最近复赛临近时间紧,就不每次都写感想和题解了,只写点有意义的好题
- CloudStack云基础架构的一些概念
1. Zones(区域) 一个区域在CloudStack配置中是最大的组织单元.一个区域通常代表一个单独的数据中心,虽然在一个数据中心也允许有多个区域.将基础架构设施加入到区域中的好处是提供物理隔离和 ...
- java 项目 导入成功后jsp页面报错处理方法
本人新导入一个maven项目可是jsp页面一直报错,我先按照网上的经验操作如下步骤: 在pom.xml配置文件中添加上javax.servlet的相关依赖: <dependency> & ...
- 通过案例快速学会Picasso图片缓存库
picasso是Square公司开源的一个Android图形缓存库,官网地址http://square.github.io/picasso/,可以实现图片下载和缓存功能. 下载地址:ht ...
- 更新 hadoop eclipse 插件
卸载hadoop 1.1.2插件.并安装新版hadoop 2.2.0插件. 假设直接删除eclipse plugin文件夹下的hadoop 1.1.2插件,会导致hadoop 1.1.2插件残留在ec ...
- js php 数组比較
php 与 javascript 数组除了定义以及 操作上有非常大的差别,还有非常多其他的差别.如今我们就来讨论讨论. 1.大家都知道php比較两个数组是否全相等(值,索引)相等 $a=arra ...