题目: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. 打造个人的vimIDE

    环境说明 系统版本:centos7.Ubuntu16 vim版本:7.4 安装git工具 整体说明:本文的vim配置是针对Linux的单个系统用户,python的自动补全使用的是 jedi-vim 插 ...

  2. 洛谷——P2007 魔方

    P2007 魔方 常神牛家的魔方都是3*3*3的三阶魔方,大家都见过. 模拟即可: #include<iostream> #include<cstdio> #include&l ...

  3. UVA - 11175 From D to E and Back(思路)

    题目: 思路: 如图E:图中a.b.c.d是有向图D中的顶点,如果ac.bc都指向cd,而ac又指向ce,那bc同样应该有一条指向ce的边不然就不能从图D转换来.所以直接枚举顶点就可以了. 代码: # ...

  4. The content of element type "resultMap" must match ...

    mybatis中的mapper文件错误 ①错误原因: <resultMap>标签中需要按照一下顺序编写: <id> <result> <association ...

  5. calculate Cp history (from Fluent) using Matlab

    input data : unscaled time history of moment/thrust from ANSYS fluent example of input data, "m ...

  6. orcad中注意的事情

    1.地的标识不能放到已经分配了网络的线上. 在用orcad画原理图的时候,把电源放到网络的时候需要特别的注意,如果,将电源地直接放到线上,而这根线又已经被分配了网络标号,那这个地会随已经分配了的网络号 ...

  7. 【GC概述以及查看堆内存使用】Java内存管理和GC学习

    内存划分 1.JAVA内存主要划分为方法栈.方法区.堆. 2.方法栈上内存会自动释放: 3.方法区上主要加载了类的元信息.静态变量.常量.改区域又称为持久代(Perm Gen),默认是最小16M,最大 ...

  8. Quartz原理解密

    Quartz原理解密 Author: Dorae Date:2018年7月17日15:55:02 转载请注明出处 一.quartz概述 quartz是一个用java实现的开源任务调度框架,可以用来创建 ...

  9. Oracle Multitenant Environment (五) Create PDB

    Creating and Removing PDBs with SQL*Plus This chapter contains the following topics: About Creating ...

  10. Swift: 转换NSString to String

    如下代码获取一个String?的结果 let s = NSString(data: data, encoding: encoding) return s as? String