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

然后tarjan缩点,一个scc里的终端是要一起推迟的,scc内点数为新图点权

根据贪心的思想,在缩完点的DAG里,一定是出度为0的点能获得更小的值,因为出度不为零的点还要加上出边所能到的点的点权

直接在出度为0的点里取min,然后记一下更新答案的新点,最后把属于这个新点的点的编号输出即可

#include<iostream>
#include<cstdio>
using namespace std;
const int N=1000005;
int n,m,q,a[N],h[N],cnt,low[N],dfn[N],tot,bl[N],col,s[N],top,d[N],va[N],mn=1e9,w;
bool v[N];
struct qwe
{
int ne,no,to;
}e[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void add(int u,int v)
{
cnt++;
e[cnt].ne=h[u];
e[cnt].no=u;
e[cnt].to=v;
h[u]=cnt;
}
void tarjan(int u)
{
dfn[u]=low[u]=++tot;
v[s[++top]=u]=1;
for(int i=h[u];i;i=e[i].ne)
{
if(!dfn[e[i].to])
{
tarjan(e[i].to);
low[u]=min(low[u],low[e[i].to]);
}
else if(v[e[i].to])
low[u]=min(low[u],dfn[e[i].to]);
}
if(low[u]==dfn[u])
{
col++;
while(s[top]!=u)
{
bl[s[top]]=col;
va[col]++;
v[s[top--]]=0;
}
bl[s[top]]=col;
va[col]++;
v[s[top--]]=0;
}
}
int main()
{
n=read(),m=read(),q=read();
for(int i=1;i<=n;i++)
a[i]=read();
for(int i=1;i<=m;i++)
{
int x=read(),y=read();
if((a[x]+1)%q==a[y])
add(x,y);
if((a[y]+1)%q==a[x])
add(y,x);
}
for(int i=1;i<=n;i++)
if(!dfn[i])
tarjan(i);
for(int i=1;i<=cnt;i++)
if(bl[e[i].no]!=bl[e[i].to])
d[bl[e[i].no]]++;
for(int i=1;i<=col;i++)
if(!d[i]&&va[i]<mn)
mn=va[i],w=i;
printf("%d\n",mn);
for(int i=1;i<=n;i++)
if(bl[i]==w)
printf("%d ",i);
return 0;
}

codeforces 949C - Data Center Maintenance【tarjan】的更多相关文章

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

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

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

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

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

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

  4. codeforces 402E - Strictly Positive Matrix【tarjan】

    首先认识一下01邻接矩阵k次幂的意义:经过k条边(x,y)之间的路径条数 所以可以把矩阵当成邻接矩阵,全是>0的话意味着两两之间都能相连,也就是整个都要在一个强连通分量里,所以直接tarjan染 ...

  5. Codeforces 950E Data Center Maintenance ( 思维 && 强连通分量缩点 )

    题意 : 给出 n 个点,每个点有一个维护时间 a[i].m 个条件,每个条件有2个点(x,y)且 a[x] != a[y].选择最少的 k (最少一个)个点,使其值加1后,m个条件仍成立. 分析 : ...

  6. Codeforces 950.E Data Center Maintenance

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

  7. MySQL frm+ibd文件还原data的办法【数据恢复】

    MySQL frm+ibd文件还原data的办法[数据恢复] 此方法只适合innodb_file_per_table          = 1 当误删除ibdata 该怎么办? 如下步骤即可恢复: 1 ...

  8. 170. Two Sum III - Data structure design【easy】

    170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...

  9. [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】

    [CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...

随机推荐

  1. STM32F407 GPIO 库函数编程套路(led与beep总结) 个人笔记

    本文由正点原子STM32F407探索者开发板的led和beep实验,总结了gpio编程的套路. 下文中以hardware 来称呼可能的硬件外设,如led或beep等. 新建项目后主要用到三个文件:ha ...

  2. Linux下汇编语言学习笔记51 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  3. linux 磁盘阵列

    1.独立磁盘冗余阵列 (RAID) 2.RAID级别: raid0 扩展卷 (条带卷) 至少一块硬盘 具有较高的存储性能 数据请求多块硬盘并行应答 连续数据分散到多个磁盘存储 ,一块磁盘坏掉所有文件就 ...

  4. 本地配置nginx的https

    前文:因为要用谷歌下的getUserMedia方法,而getUserMedia方法只能在https下才能调用,所以在本地搭建https来测试,现在说说步骤. 步骤1:下载nginx-1.10.3.zi ...

  5. Subsets and Subsets II (回溯,DFS,组合问题)

    Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...

  6. 18.9.22 noip模拟赛

    此题为找规律.期望100 实际100 #include<cstdio> #include<cstring> #include<iostream> #include& ...

  7. Vuzzer自动漏洞挖掘工具简单分析附使用介绍

    Vuzzer 是由计算机科学机构  Vrije Universiteit Amsterdam.Amsterdam Department of Informatics 以及 International ...

  8. [php learn] php 从头開始学习1

    前言:大概在2006年的时候,学习过一段时间的php.而且当时做了一个下载的站点,后来因为读研究生阶段用的是java.j2ee相关,所以php就搁浅掉了,php这些年也发生了非常大的变化,最大一个变化 ...

  9. Mac OS 10.10.3下Apache + mod_wsgi配置【一】

    [一] 首先,MAC是自带Apache的,在/private/etc/apache2路径下,能够使用apachectl -v查看版本号.我的版本号例如以下: Server version: Apach ...

  10. java web中的session属性范围和request属性范围

    首先必需要了解client跳转和server端跳转的差别: client跳转: response.sendRedict(String path).地址栏发生改变. 不能传递request属性. ser ...