cf950e Data Center Maintenance
若推迟 \(u\) 必推迟 \(v\),则连边 <\(u,v\)>。
求强联通分量后缩点,答案显然是出度为 \(0\) 且 size 最小的 scc。
#include <iostream>
#include <cstdio>
using namespace std;
int n, m, h, a[100005], dfn[100005], uu, vv, loo[100005], bel[100005], scc, hav[100005], sta[100005], din, tot;
int hea[100005], cnt, ru[100005], ans=0x3f3f3f3f, chu[100005], minn;
bool ins[100005];
struct Edge{
int too, nxt;
}edge[200005];
void add_edge(int fro, int too){
edge[++cnt].nxt = hea[fro];
edge[cnt].too = too;
hea[fro] = cnt;
}
void tarjan(int x){
sta[++din] = x;
ins[x] = true;
dfn[x] = loo[x] = ++tot;
for(int i=hea[x]; i; i=edge[i].nxt){
int t=edge[i].too;
if(!dfn[t]){
tarjan(t);
loo[x] = min(loo[x], loo[t]);
}
else if(ins[t])
loo[x] = min(loo[x], dfn[t]);
}
if(dfn[x]==loo[x]){
int j;
scc++;
do{
j = sta[din--];
bel[j] = scc;
hav[scc]++;
ins[j] = false;
}while(dfn[j]!=loo[j]);
}
}
int main(){
cin>>n>>m>>h;
for(int i=1; i<=n; i++)
scanf("%d", &a[i]);
for(int i=1; i<=m; i++){
scanf("%d %d", &uu, &vv);
if((a[uu]+1)%h==a[vv]) add_edge(uu, vv);
if((a[vv]+1)%h==a[uu]) add_edge(vv, uu);
}
for(int i=1; i<=n; i++)
if(!dfn[i])
tarjan(i);
for(int i=1; i<=n; i++)
for(int j=hea[i]; j; j=edge[j].nxt){
int t=edge[j].too;
if(bel[i]!=bel[t])
chu[bel[i]]++;
}
for(int i=1; i<=scc; i++)
if(!chu[i] && ans>hav[i]){
ans = hav[i];
minn = i;
}
cout<<ans<<endl;
for(int i=1; i<=n; i++)
if(bel[i]==minn)
printf("%d ", i);
printf("\n");
return 0;
}
cf950e Data Center Maintenance的更多相关文章
- Codeforces 950.E Data Center Maintenance
E. Data Center Maintenance time limit per test 1 second memory limit per test 512 megabytes input st ...
- 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 缩 ...
- Codeforces Round #469 (Div. 2) E. Data Center Maintenance
tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...
- codeforce469DIV2——E. Data Center Maintenance
题意: 有n个数据中心,m个客户,每天有h个小时,其中 n,m,h<=100000.每个数据中心i每天都会有一个数据维护的时间0<=u[i]<=h-1,在数据中心维护期间时不可以使用 ...
- Codeforces 950E Data Center Maintenance 强连通分量
题目链接 题意 有\(n\)个信息中心,每个信息中心都有自己的维护时间\((0\leq t\lt h)\),在这个时刻里面的信息不能被获得. 每个用户的数据都有两份备份,放在两个相异的信息中心(维护时 ...
- CF 949C Data Center Maintenance——思路+SCC
题目:http://codeforces.com/contest/949/problem/C 可以想到可能是每组c有连边的可能. 但别直接给c1.c2连边,那样之后会变得很不好做. 可以把一些限制放在 ...
- [CF949C]Data Center Maintenance
题目大意:$n$个点,每个点有一个值$w_i$.$m$个条件,每个条件给出$x,y$,要求$w_x\not =w_y$.选择最少的点,使其值加$1$后,所有条件成立(数据保证有解). 题解:对于每个条 ...
- Data Center Maintenance CodeForces - 950E
http://codeforces.com/contest/950/problem/E 贴一份板子 #include<cstdio> #include<vector> #inc ...
- codeforces 949C - Data Center Maintenance【tarjan】
首先转换图论模型,把某个客户一个终端的维修时间(+1)%h之后和另一个终端维修时间一样,这样的两个终端连一条有向边,表示推后一个终端就必须推后另一个 然后tarjan缩点,一个scc里的终端是要一起推 ...
随机推荐
- On the way to the park Gym - 101147I 几何
http://codeforces.com/gym/101147/problem/I I. On the way to the park time limit per test 5 seconds m ...
- Linux sftp用法
sftp用法 1. 用sftp如何登录服务器 sftp 是一个交互式文件传输程式.它类似于 ftp, 但它进行加密传输,比FTP有更高的安全性.下边就简单介绍一下如何远程连接主机,进行文件的上传和下载 ...
- ListBox,CheckBoxList,DropDownList,RadioButtonList的常见数据绑定
ListBox,CheckBoxList,DropDownList,RadioButtonList的常见用法 四个都是选择控件,用法大同小异,基本都是指定键值对: 直接加选择项: void way1( ...
- 打开一个本地apk进行安装
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); File file = new File(Environment ...
- 在前台引用JSON对象
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script&g ...
- HDU 6052 To my boyfriend(容斥+单调栈)
题意:对于一个n*m的方格,每个格子中都包含一种颜色,求出任意一个矩形包含不同颜色的期望. 思路: 啊啊啊啊啊,补了两天,总算A了这道题了,简直石乐志,前面的容斥还比较好写,后面的那个>13那个 ...
- 用valgrind检查内存问题
Valgrind Valgrind作为一个免费且优秀的工具包,平时大部分人可能都是使用valgrind检测内存问题,如内存泄露,越界等. Valgrind工具包包含多个工具,如Memcheck,Cac ...
- for..in...时,注意hasOwnProperty验证
for..in...时,注意hasOwnProperty验证 var obj = { a: 10, b: 20 }; // 注意词句代码 Object.prototype.c = 30; var it ...
- JdbcTemplate类对sql的操作使用
<!--方式一: dbcp 数据源配置,在测试环境使用单连接 --> <bean id="dataSource" class="org.apache.c ...
- XDB基于Library的备份及恢复
基于standalone全备份 语句: xdb backup --federation xhive://localhost:1235 --standalone --file E:\xdbData\xD ...