Codeforces Round #469 (Div. 1) 949C C. Data Center Maintenance (Div. 2 950E)
题
OvO http://codeforces.com/contest/949/problem/C
codeforces 949C 950E
解
建图,记原图为 G1,缩点,记缩完点后的新图为G2
缩完点后的图 G2 必定无环,求这个无环图 G2 中每个点的入度,
找出入度为 的那些点,记这些点的集合为 S,然后把 S 中这些点映射到 G1 中,则这些点各自对应一个点集。S 的各点中,对应的最小集合即为所求集合
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <vector>
#include <stack> using namespace std; const int N=100044;
const int INF=1e9+44; struct data
{
int to,next;
} tu[N*2]; struct sav
{
int a,b;
} edgsav[N*2]; int head[N];
int ip;
int dfn[N], low[N];///dfn[]表示深搜的步数,low[u]表示u或u的子树能够追溯到的最早的栈中节点的次序号
int sccno[N];///缩点数组,表示某个点对应的缩点值
int step;
int scc_cnt;///强连通分量个数
int n,m,h,u[N];
int ind[N],outd[N];
int edgnum; void init()
{
ip=0;
edgnum=0;
memset(head,-1,sizeof(head));
memset(ind,0,sizeof(ind));
memset(outd,0,sizeof(outd));
} void add(int u,int v)
{
edgnum++,edgsav[edgnum].a=u,edgsav[edgnum].b=v;
tu[ip].to=v,tu[ip].next=head[u],head[u]=ip++;
} vector<int> scc[N];///得出来的缩点,scc[i]里面存i这个缩点具体缩了哪些点
stack<int> S; void dfs(int u)
{
dfn[u] = low[u] = ++step;
S.push(u);
for (int i = head[u]; i !=-1; i=tu[i].next)
{
int v = tu[i].to;
if (!dfn[v])
{
dfs(v);
low[u] = min(low[u], low[v]);
}
else if (!sccno[v])
low[u] = min(low[u], dfn[v]);
}
if (low[u] == dfn[u])
{
scc_cnt += 1;
scc[scc_cnt].clear();
while(1)
{
int x = S.top();
S.pop();
if (sccno[x] != scc_cnt) scc[scc_cnt].push_back(x);
sccno[x] = scc_cnt;
if (x == u) break;
}
}
} void tarjan(int n)
{
memset(sccno, 0, sizeof(sccno));
memset(dfn, 0, sizeof(dfn));
step = scc_cnt = 0;
for (int i = 1; i <=n; i++)
if (!dfn[i]) dfs(i);
} inline int trans(int x)
{
return (x+1)%h;
} int main()
{
int a,b;
init();
scanf("%d%d%d",&n,&m,&h);
for(int i=1;i<=n;i++)
scanf("%d",&u[i]);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&a,&b);
if(trans(u[a])==u[b]) add(a,b);
if(trans(u[b])==u[a]) add(b,a);
}
tarjan(n);
for(int i=1;i<=edgnum;i++)
if(sccno[edgsav[i].a]!=sccno[edgsav[i].b])
{
outd[sccno[edgsav[i].a]]++;
ind[sccno[edgsav[i].b]]++;
}
int the,tmp=INF;
for(int i=1;i<=scc_cnt;i++)
if(outd[i]==0 && scc[i].size()<tmp)
the=i,tmp=scc[i].size();
printf("%d\n",tmp);
for(int i=0;i<scc[the].size();i++)
{
printf("%d",scc[the][i]);
if(i==scc[the].size()-1) puts("");
else printf(" ");
}
return 0;
}
Codeforces Round #469 (Div. 1) 949C C. Data Center Maintenance (Div. 2 950E)的更多相关文章
- CF949C Data Center Maintenance(建图+强联通分量)
题意 有 n 个信息中心,第 i 个信息中心要在第 ti 个小时维护,维护期间信息不能被获得. 每个用户的数据都有两份备份,第 i 个用户的数据放在信息中心 c(i,1) 和 c(i,2). 现在要挑 ...
- Codeforces Round #469 (Div. 2)
Codeforces Round #469 (Div. 2) 难得的下午场,又掉分了.... Problem A: 怎么暴力怎么写. #include<bits/stdc++.h> #de ...
- Codeforces Round #469 Div. 2 A B C D E
A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...
- Codeforces Round #469 Div. 2题解
A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...
- Codeforces 950.E Data Center Maintenance
E. Data Center Maintenance time limit per test 1 second memory limit per test 512 megabytes input st ...
- Docker Data Center系列(一)- 快速搭建云原生架构的实践环境
本系列文章演示如何快速搭建一个简单的云原生架构的实践环境. 基于这个基础架构,可以持续部署微服务架构的应用栈,演练敏捷开发过程,提升DevOps实践能力. 1 整体规划 1.1 拓扑架构 1.2 基础 ...
- Docker Data Center系列(二)- UCP安装指南
本系列文章演示如何搭建一个mini的云平台和DevOps实践环境. 基于这套实践环境,可以部署微服务架构的应用栈,演练提升DevOps实践能力. 1 系统要求 1.1 硬件和软件要求 Linux内核版 ...
- Docker Data Center系列(四)- 离线安装UCP和DTR
本系列文章演示如何搭建一个mini的云平台和DevOps实践环境. 基于这套实践环境,可以部署微服务架构的应用栈,演练提升DevOps实践能力. 1 离线安装UCP 1.1 可用版本 Version ...
- Docker Data Center系列(三)- DTR安装指南
本系列文章演示如何搭建一个mini的云平台和DevOps实践环境. 基于这套实践环境,可以部署微服务架构的应用栈,演练提升DevOps实践能力. 1 系统要求 1.1 硬件和软件要求 成为UCP管理的 ...
随机推荐
- (一)CXF之发布第一个WebService服务
一.CXF入门 1.1 前提 Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS .这些 ...
- (二十六)JavaBean
一.定义 1 JavaBean是一个遵循特定写法的Java类,它通常具有如下特点: 这个Java类必须具有一个无参的构造函数 属性必须私有化. 私有化的属性必须通过public类型的方法暴露给其它程序 ...
- (八)装配Bean(2)
二.在Java类中进行显式的装配 显式配置有两种: 1. 一种是在java(本文讲解) 2. 另一种是xml配置文件(第一章有讲) 案例一: 使用java显式装配+@autowired自动装配的方 ...
- (二)SpringBoot之springboot开发工具的使用以及springboot插件的功能
一.springboot开发工具的使用 1.1 在项目中添加springoot开发工具 1.2 功能 修改代码后点击保存自动重启 二.springboot插件的功能 2.1 maven配置 <p ...
- SQL Server系统函数:系统信息函数
原文:SQL Server系统函数:系统信息函数 1.会话id,服务器信息.用户信息 select @@SPID, --返回当前连接的会话ID:SPID @@servername, --SQL Ser ...
- 【原创】大叔经验分享(84)spark sql中设置hive.exec.max.dynamic.partitions无效
spark 2.4 spark sql中执行 set hive.exec.max.dynamic.partitions=10000; 后再执行sql依然会报错: org.apache.hadoop.h ...
- MyBatis核心组件
SqlSessionFactoryBuilder (构造器) 会根据配置或者代码来生成SqlSessionFactory SqlSessionFactory (工厂接口) 以后他来生成SqlSessi ...
- Python练习_数据类型_day4
题目 1.作业 1,写代码,有如下列表,按照要求实现每一个功能 li = ["alex", "WuSir", "ritian", " ...
- MySql8.0 安装重要的两步。
1.去官网下载mysql社区版 windows安装包. 2.在安装包 安装的过程中,有一步就是启动mysql 会失败: 然后修改服务后,再次回到安装界面点击:execute,就会成功了. 先去配置一下 ...
- javascript新特性
让我们看看javascript中的一些新特性.本文将介绍它们的语法和相关链接,以帮助读者及时了解它们的进展.我们将通过编写一个小测试项目来演示如何快速使用这些新功能! 关于提案 提案分为五个阶段.有关 ...