题目:http://codeforces.com/contest/949/problem/C

可以想到可能是每组c有连边的可能。

但别直接给c1、c2连边,那样之后会变得很不好做。

可以把一些限制放在连边这个环节上。

也就是只有(c1+1)%h==c2才从c1向c2连边表示选了c1必须选c2!c2向c1也是一样。

然后缩个点找无出度的最小的点就行了。

边注意开成两倍——一组c也可能连两条边,%2之类的。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e5+;
int n,m,h,a[N],hd[N],xnt,dfn[N],low[N],tim;
int stack[N],top,cnt,col[N],siz[N],cd[N],ans=0x3f3f3f3f,prn;
bool ins[N];
struct Ed{
int nxt,fr,to;
Ed(int n=,int f=,int t=):nxt(n),fr(f),to(t) {}
}ed[N<<];//!!!有可能(%2,一个c连两条边)
void add(int x,int y)
{
ed[++xnt]=Ed(hd[x],x,y);hd[x]=xnt;
}
void tarjan(int cr,int f)
{
dfn[cr]=low[cr]=++tim;
stack[++top]=cr;ins[cr]=;
for(int i=hd[cr],v;i;i=ed[i].nxt)
if(ins[v=ed[i].to])low[cr]=min(low[cr],dfn[v]);//directed edge,don't worry fa
else if(!dfn[v])tarjan(v,cr),low[cr]=min(low[cr],low[v]);
if(dfn[cr]==low[cr])
{
cnt++;
while(stack[top]!=cr)col[stack[top]]=cnt,ins[stack[top--]]=,siz[cnt]++;
top--;col[cr]=cnt;ins[cr]=;siz[cnt]++;
}
}
int main()
{
scanf("%d%d%d",&n,&m,&h);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
int x,y;
for(int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
if((a[x]+)%h==a[y])add(x,y);if((a[y]+)%h==a[x])add(y,x);
}
for(int i=;i<=n;i++)if(!dfn[i])tarjan(i,);
for(int i=,v;i<=xnt;i++)
if((v=col[ed[i].fr])!=col[ed[i].to])cd[v]++;
for(int i=;i<=cnt;i++)
if(!cd[i]&&siz[i]<ans)ans=siz[i],prn=i;
printf("%d\n",ans);
for(int i=;i<=n;i++)
if(col[i]==prn)printf("%d ",i);
return ;
}

CF 949C Data Center Maintenance——思路+SCC的更多相关文章

  1. codeforces 949C - Data Center Maintenance【tarjan】

    首先转换图论模型,把某个客户一个终端的维修时间(+1)%h之后和另一个终端维修时间一样,这样的两个终端连一条有向边,表示推后一个终端就必须推后另一个 然后tarjan缩点,一个scc里的终端是要一起推 ...

  2. CF 949C Data Center Maintenance_强联通分量_思维题

    题意: 某土豪公司建立了n个数据中心,把m份资料每份在其中的两个数据中心备份. 每个数据中心在一天h个小时当中有一个小时需要维护,此时不提供资料下载服务. 现在土豪公司想要将其中若干个数据中心的维护时 ...

  3. Codeforces 949C(Data Center Maintenance,Tarjan缩点)

    难度系数:1900 graphs 题意:有 n 个银行,m 个客户,每个客户都把自己的资料放在 2 个银行,一天总共有 h 小时,每个银行每天都要维护一小时,这一小时内银行无法工作,但是这一小时客户仍 ...

  4. Codeforces 950.E Data Center Maintenance

    E. Data Center Maintenance time limit per test 1 second memory limit per test 512 megabytes input st ...

  5. 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 缩 ...

  6. Codeforces 950E Data Center Maintenance 强连通分量

    题目链接 题意 有\(n\)个信息中心,每个信息中心都有自己的维护时间\((0\leq t\lt h)\),在这个时刻里面的信息不能被获得. 每个用户的数据都有两份备份,放在两个相异的信息中心(维护时 ...

  7. codeforce469DIV2——E. Data Center Maintenance

    题意: 有n个数据中心,m个客户,每天有h个小时,其中 n,m,h<=100000.每个数据中心i每天都会有一个数据维护的时间0<=u[i]<=h-1,在数据中心维护期间时不可以使用 ...

  8. cf950e Data Center Maintenance

    若推迟 \(u\) 必推迟 \(v\),则连边 <\(u,v\)>. 求强联通分量后缩点,答案显然是出度为 \(0\) 且 size 最小的 scc. #include <iostr ...

  9. CF949 C Data Center Maintenance——边双连通分量

    题目:http://codeforces.com/contest/949/problem/C 把一个点指向修改它会影响到的点就可以做了: 有取模,所以多出一些要注意的地方,首先是可能出现环,所以需要 ...

随机推荐

  1. [转]AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)

    AOP那些学术概念—通知.增强处理连接点(JoinPoint)切面(Aspect) 1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充 ...

  2. library-type:fr-unstanded vs fisrt-stand vs second-stanrd

    建库时是否是链特异性建库. Tophat2: --library-type The default is unstranded (fr-unstranded). If either fr-firsts ...

  3. MySQL实验1: 新建一个名为 library 的数据库,包含 book、reader 两张表,根据自己的理解安排表的内容并插入数据。

    数据表(table)简称表,它是数据库最重要的组成部分之一.数据库只是一个框架,表才是实质内容. 实验: 新建一个名为 library的数据库,包含 book.reader两张表,根据自己的理解安排表 ...

  4. Kubernetes busybox nslookup问题

    使用最新版本的busybox会出现nslookup提示无法解析的问题: Server: 10.96.0.10 Address: 10.96.0.10:53 ** server can't find k ...

  5. 安装使用snmp监控命令

    1.安装snmp windows下载安装https://sourceforge.net/projects/net-snmp/ centos yum install -y net-snmp net-sn ...

  6. Loop through an array in JavaScript

    https://stackoverflow.com/questions/3010840/loop-through-an-array-in-javascript?page=1&tab=votes ...

  7. Flume-NG启动过程源码分析(一)(原创)

    从bin/flume 这个shell脚本可以看到Flume的起始于org.apache.flume.node.Application类,这是flume的main函数所在. main方法首先会先解析sh ...

  8. openstack havana块存储Cinder磁盘加密方法研究

    http://blog.csdn.net/cloudresearch/article/details/19092219 在openstack havana的release note中有如下介绍“Att ...

  9. js科里化

    科里化定义如下: 首先将一批函数转入一个函数(然后这个函数返回一个新的函数),这中形式就叫“做科里化”(currying) Function.prototype.curry = function(){ ...

  10. 企业环境中部署 ActiveMQ

    这一章讲述了怎么配置 ActiveMQ 集群.