Explosion at Cafebazaar
Explosion at Cafebazaar
时间限制: 1 Sec 内存限制: 128 MB
题目描述
Assume that at time t = 0, all the switches are in sending mode and have an empty buffer except switch i which stores a 1-bit package of data in its buffer. Also, all the switches change their modes after each second, so at time t = 1 all the switches change to receiving mode, at time t = 2 they change to sending mode, and so on. Switch i is called explosive if the maximum length of data stored in the buffers of switches is not bounded as t goes to infinity.
Your task is to calculate the number of explosive switches in the network.
输入
输出
样例输入
3 3
1 2
2 3
3 1
5 6
1 2
2 3
3 1
3 4
4 5
5 3
4 5
1 2
2 3
3 2
3 2
3 4
0 0
样例输出
0
5
3
来源/分类
题意:在n个点m条边的图中,每个点可以沿有向边发送数据,当然每个点也可以接收数据。每个点发送数据后,该点的数据就会清零,图中所有点发送和接收数据是同步的。(即它们一起发送数据,一起接收数据)。问在哪些点放上单位数据,可以使图中某些点的数据量达到无穷大。
#include<bits/stdc++.h>
#define N 50050
using namespace std; int dfn[N],low[N],vis[N],color[N],now_clock,now_color;
int Stack[N],top;
vector<int>edges[N];
int explosive[N],du[N],sum_point[N],dfs2_vis[N],ans;
vector<int>newedges[N];
vector<int>edges2[N]; void init(int n)
{
for(int i=;i<=n;i++)edges[i].clear(),newedges[i].clear(),edges2[i].clear();
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(vis,,sizeof(vis));
memset(explosive,,sizeof(explosive));
memset(du,,sizeof(du));
memset(sum_point,,sizeof(sum_point));
memset(dfs2_vis,,sizeof(dfs2_vis));
now_clock=;
top=;
now_color=;
ans=; } void dfs(int x)
{
dfn[x]=low[x]=now_clock++;
vis[x]=;
Stack[++top]=x; int Size=edges[x].size();
for(int i=;i<Size;i++)
{
int v=edges[x][i];
if(!dfn[v])
{
dfs(v);
low[x]=min(low[x],low[v]);
}
else
if(vis[v])low[x]=min(low[x],dfn[v]);
} if(dfn[x]==low[x])
{
while(Stack[top]!=x)
{
vis[Stack[top]]=;
color[Stack[top]]=now_color;
top--;
} vis[Stack[top]]=;
color[Stack[top]]=now_color++;
top--;
}
} void dfs2(int x)
{
if(!dfs2_vis[x])
{
dfs2_vis[x]=;
ans+=sum_point[x];
} int Size=newedges[x].size();
for(int i=;i<Size;i++)
if(!dfs2_vis[newedges[x][i]])
dfs2(newedges[x][i]); } int dfs3(int x)
{
if(sum_point[x]>=)return ; int Size=edges2[x].size();
for(int i=;i<Size;i++)
if(dfs3(edges2[x][i]))return ; return ;
} int main()
{ int n,m;
while(scanf("%d %d",&n,&m)==)
{
if(!n)return ; init(n); while(m--)
{
int u,v;
scanf("%d %d",&u,&v);
edges[u].push_back(v);
} for(int i=;i<=n;i++)
if(!dfn[i])dfs(i); for(int i=;i<=n;i++)
{
int Size=edges[i].size();
for(int j=;j<Size;j++)
{
int u=i,v=edges[i][j];
if(color[u]==color[v])
du[v]++; }
} for(int i=;i<=n;i++)
{
sum_point[color[i]]++;
if(du[i]>=)explosive[color[i]]=;
}
/* for(int i=1;i<=n;i++)printf("%d ",color[i]);
printf("\n");
for(int i=1;i<now_color;i++)printf("%d ",sum_point[i]);
printf("\n");
for(int i=1;i<now_color;i++)printf("%d ",explosive[i]);
printf("\n");
*/
for(int i=;i<=n;i++)
{
int Size=edges[i].size();
for(int j=;j<Size;j++)
{
int u=i,v=edges[i][j];
if(color[u]!=color[v])
{
newedges[color[v]].push_back(color[u]);
edges2[color[u]].push_back(color[v]);
}
}
} for(int i=;i<now_color;i++)
if(!explosive[i]&&sum_point[i]>=)
{
int Size=edges2[i].size();
for(int j=;j<Size;j++)
if(dfs3(edges2[i][j]))
{
explosive[i]=;
break;
}
} for(int i=;i<now_color;i++)
if(explosive[i])dfs2(i); printf("%d\n",ans);
} return ;
}
Explosion at Cafebazaar的更多相关文章
- 2016 ACM ICPC Asia Region - Tehran
2016 ACM ICPC Asia Region - Tehran A - Tax 题目描述:算税. solution 模拟. B - Key Maker 题目描述:给出\(n\)个序列,给定一个序 ...
- NBUT 1635 Explosion(最小顶点覆盖)
[1635] Explosion 时间限制: 10000 ms 内存限制: 65535 K 问题描述 there is a country which contains n cities connec ...
- Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)
E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input out ...
- 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp
2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp [P ...
- upc组队赛3 Chaarshanbegaan at Cafebazaar
Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...
- hdu 5036 Explosion(概率期望+bitset)
Problem Description Everyone knows Matt enjoys playing games very much. Now, he to N. Input The firs ...
- HDU - 5036 Explosion
Problem Description Everyone knows Matt enjoys playing games very much. Now, he is playing such a ga ...
- hdu5306 Explosion
题目链接 题意 有n个房间,每个房间里面有若干把钥匙,每把钥匙可以打开对应的一扇门.如果手中没有钥匙,就要随机轰炸一个房间来打开这个房间.如果有钥匙,就要去打开这些房间.问期望轰炸次数是多少. 思路 ...
- HDU 5036 Explosion (传递闭包+bitset优化)
<题目链接> 题目大意: 一个人要打开或者用炸弹砸开所有的门,每个门后面有一些钥匙,一个钥匙对应一个门,告诉每个门里面有哪些门的钥匙.如果要打开所有的门,问需要用的炸弹数量为多少. 解题分 ...
随机推荐
- 洛谷 First Step (ファーストステップ) 3月月赛T1
题目背景 知らないことばかりなにもかもが(どうしたらいいの?) 一切的一切 尽是充满了未知数(该如何是好) それでも期待で足が軽いよ(ジャンプだ!) 但我仍因满怀期待而步伐轻盈(起跳吧!) 温度差なん ...
- elasticsearch最全详细使用教程:入门、索引管理、映射详解、索引别名、分词器、文档管理、路由、搜索详解
一.快速入门1. 查看集群的健康状况http://localhost:9200/_cat http://localhost:9200/_cat/health?v 说明:v是用来要求在结果中返回表头 状 ...
- 一个batch如何通过一个网络
一个batch下所有的图片一起经过整个网络,不是说一张图片经过网络后再让下一张进入网络,这样一个batch一起通过网络计算速度比一张一张这样快
- VC-基础:VC++动态链接库(DLL)编程深入浅出
1.概论 先来阐述一下DLL(Dynamic Linkable Library)的概念,你可以简单的把DLL看成一种仓库,它提供给你一些可以直接拿来用的变量.函数或类.在仓库的发展史上经历了“无库-静 ...
- javase(6)_异常
一.异常的概念 1.java异常是Java提供的用于处理程序中错误的一种机制. 2.所谓错误是程序在运行过程中发生的一些异常事件(如:除0,数组下标越界,文件不存在等). 3.Java程序的执行过程中 ...
- Mac 录制视频,并转为GIF格式
内容中包含 base64string 图片造成字符过多,拒绝显示
- bzoj5286 [Hnoi2018]转盘
题目描述: bz luogu 题解: 看了半个晚上终于明白了. 首先最优决策一定有:在起始点停留一段时间然后一直前进. 解释网上有很多,在这里不赘述了. (由于是环,先把$T$数组倍长.) 首先基于决 ...
- 编译openwrt_MT7688_hiwooya
参考链接: 无涯论坛地址: http://www.hi-wooya.com/forum.php openwrt官网地址:https://openwrt.org/zh-cn/doc/howto/buil ...
- modprode
modprobe命令 1.modprobe 命令是根据depmod -a的输出/lib/modules/version/modules.dep来加载全部的所需要模块. 2.删除模块的命令是:modpr ...
- 在已编译安装nginx上动态添加模块
一.添加nginx模块 找到安装nginx的源码根目录,如果没有的话下载新的源码 wget http://nginx.org/download/nginx-1.8.1.tar.gz 查看ngixn版本 ...