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

把一个点指向修改它会影响到的点就可以做了;

有取模,所以多出一些要注意的地方,首先是可能出现环,所以需要 tarjan 求边双;

其次,边集数组的大小应该开成两倍,因为取模可能导致一对 ci 互相连边;

然后找出不影响别的点的、最小的边双,输出即可;

而我竟然把 tarjan 都少写了一个 top-- !真是对自己无语了...

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int const maxn=1e5+;
int n,m,h,a[maxn],hd[maxn],cr,ct,col[maxn],sta[maxn],top,dfn[maxn],low[maxn],tim,deg[maxn];
bool vis[maxn];
vector<int>scc[maxn];
struct N{
int to,nxt;
N(int t=,int n=):to(t),nxt(n) {}
}ed[maxn<<];
void add(int x,int y){ed[++ct]=N(y,hd[x]); hd[x]=ct;}
void tarjan(int x)
{
dfn[x]=low[x]=++tim; sta[++top]=x; vis[x]=;
for(register int i=hd[x];i;i=ed[i].nxt)
{
int u=ed[i].to;
if(!dfn[u])
{
tarjan(u); low[x]=min(low[x],low[u]);
}
else if(vis[x])low[x]=min(low[x],dfn[u]);
}
if(low[x]==dfn[x])
{
cr++;
while(sta[top]!=x)
{
int y=sta[top]; top--;
vis[y]=; col[y]=cr;
scc[cr].push_back(y);
}
top--;//!
vis[x]=; col[x]=cr; scc[cr].push_back(x);
}
}
int main()
{
scanf("%d%d%d",&n,&m,&h);
for(register int i=;i<=n;i++)scanf("%d",&a[i]);
for(register int i=,x,y;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(register int i=;i<=n;i++)
if(!dfn[i])tarjan(i);
for(register int i=;i<=n;i++)
for(register int j=hd[i];j;j=ed[j].nxt)
{
int u=ed[j].to;
if(col[i]!=col[u])deg[col[i]]++;
}
int mn=0x3f3f3f3f,tag;
for(register int i=;i<=cr;i++)
if(!deg[i]&&scc[i].size()<mn)mn=scc[i].size(),tag=i;
printf("%d\n",scc[tag].size());
for(register int j=;j<scc[tag].size();j++)
printf("%d ",scc[tag][j]);
return ;
}

CF949 C Data Center Maintenance——边双连通分量的更多相关文章

  1. Codeforces 950.E Data Center Maintenance

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

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

  3. Codeforces Round #469 (Div. 2) E. Data Center Maintenance

    tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...

  4. codeforce469DIV2——E. Data Center Maintenance

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

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

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

  6. CF 949C Data Center Maintenance——思路+SCC

    题目:http://codeforces.com/contest/949/problem/C 可以想到可能是每组c有连边的可能. 但别直接给c1.c2连边,那样之后会变得很不好做. 可以把一些限制放在 ...

  7. [CF949C]Data Center Maintenance

    题目大意:$n$个点,每个点有一个值$w_i$.$m$个条件,每个条件给出$x,y$,要求$w_x\not =w_y$.选择最少的点,使其值加$1$后,所有条件成立(数据保证有解). 题解:对于每个条 ...

  8. cf950e Data Center Maintenance

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

  9. Data Center Maintenance CodeForces - 950E

    http://codeforces.com/contest/950/problem/E 贴一份板子 #include<cstdio> #include<vector> #inc ...

随机推荐

  1. Redis系列(四)--持久化

    持久化就是将数据的更新异步的保存到磁盘中 持久化方式: 1.快照:某个时间点数据的备份 MySQL dump.Redis RDB 2.写日志:MySQL BinLog.HBASE Hlog.Redis ...

  2. Redis系列(三)--消息队列、排行榜等

    Redis命令执行生命周期: 发送命令--->排队(单线程)--->执行命令--->返回结果 慢查询: 只是针对命令执行阶段 慢查询日志通过一个固定长度的FIFO queue,这个q ...

  3. Spring Security 介绍与Demo

    一.Spring Security 介绍 Spring Security 是针对Spring项目的安全框架,也是Spring Boot底层安全模块的默认技术选型.我们仅需引入spring-boot-s ...

  4. Group共享网元

    熟悉TWaver的用户都知道Group的概念,如果是Group,那必然会出现一个网元在多组的情况,最近有客户遇到这个问题,给写了Demo,这些也跟大家分享一下如何实现,先让我们看看共享网元的效果. 熟 ...

  5. SQL学习笔记:一些高级语句

    现在以MySQL为模板.学习的方法和别的数据库写法上会有不同,但是思路基本一致. 用到的数据库表的格式: +----+--------------+-------------------------- ...

  6. hdu 1040

    As Easy As A+B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. 【Codeforces 644A】Parliament of Berland

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] https://blog.csdn.net/V5ZSQ/article/details/70873661 看这个人的吧. [代码] #incl ...

  8. 阿里云服务器Ubuntu 16.04 3安装mysql

    .更新系统 apt-get update [注意:要在root用户下] .安装mysql-server apt-get install mysql-serverapt-get install mysq ...

  9. [luoguP2915] [USACO08NOV]奶牛混合起来Mixed Up Cows(DP)

    传送门 f[i][S] 表示当前集合为 S,最后一个数为 i 的最优解 f[i][S] += f[j][S - i] (j, i ∈ S && j != i && ab ...

  10. poj 2404 中国邮递员问题 欧拉回路判定+状压dp

    /* 状压dp 邮递员问题:求经过任意点出发经过每一条边一次并回到原点. 解法:1.如果是欧拉回路那么就是所有的边的总和. 2.一般的解法,找出所有的奇度顶点,任意两个顶点匹配,即最小完美匹配,可用状 ...