Codeforces Round #469 (Div. 2) E. Data Center Maintenance
tarjan
题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护。
现在要挑出一个数据中心的子集,把他们的维护时间都推后一个小时。问最小推几个?
建图,如果对于一个顾客,两个数据维护中心维护时间正好差一个小时,那么前者向后者连一条边。在一个强连通分量里面的所有点必须选。。如果有连向其他的强连通分量,那么那个也必须选,这种情况肯定不是最优,所以舍弃所有有出度的强连通分量。
tarjan缩点,然后判一判。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int inf = 0x3f3f3f3f;
const LL LLinf = 0x3f3f3f3f3f3f3f3f;
LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10ll+ch-'0';ch=getchar();}
return x*f;
} const int maxn = 100000 + 10;
const int maxm = 200000 + 10; struct Edge {
int to,nex;
}e[maxm]; int n,m,h;
int u[maxn];
int g[maxn],eid; void addedge(int a,int b) {
e[eid]=(Edge){b,g[a]}; g[a]=eid++;
} void build()
{
n=read(); m=read(); h=read();
for(int i=1;i<=n;i++)
{
u[i]=read();
} memset(g,-1,sizeof(g));
for(int i=1,c1,c2;i<=m;i++)
{
c1=read(); c2=read();
if((u[c1]+1)%h==u[c2])
{
addedge(c1,c2);
//printf(" %d %d\n",c1,c2);
}
if((u[c2]+1)%h==u[c1])
{
addedge(c2,c1);
//printf(" %d %d\n",c2,c1);
}
}
} int dfn[maxn],low[maxn],cnt;
bool instack[maxn];
int s[maxn],sp;
int color[maxn],cp;
int sum[maxn];
int out[maxn];
int res; void tarjan(int u)
{
dfn[u]=low[u]=++cnt;
s[++sp]=u; instack[u]=1; for(int i=g[u];~i;i=e[i].nex)
{
if(!dfn[e[i].to])
{
tarjan(e[i].to);
low[u]=min(low[u],low[e[i].to]);
}
else if(instack[e[i].to])
{
low[u]=min(low[u],dfn[e[i].to]);
}
} if(dfn[u]==low[u]) {
++cp; int v;
while(sp)
{
v=s[sp];
instack[v]=0;
color[v]=cp;
sum[cp]++;
sp--;
if(s[sp+1]==u) break;
}
}
} void solve()
{
for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
/*
for(int i=1;i<=n;i++)
printf("color[%d]=%d\n",i,color[i]);
*/
/*for(int i=1;i<=n;i++)
if(!color[i])
{
color[i]=++cp;
sum[i]=1;
}
*/
for(int u=1;u<=n;u++) { for(int i=g[u];~i;i=e[i].nex) if(color[e[i].to]!=color[u])
out[color[u]]++;
} res=0; sum[0]=inf;
for(int i=1;i<=cp;i++) {
//printf("Test %d %d\n",i,out[i]);
if(out[i]==0&&sum[i]<sum[res])
{
res=i;
}
}
printf("%d\n",sum[res]);
for(int i=1;i<=n;i++) if(color[i]==res)
printf("%d ",i);
printf("\n");
} int main()
{
build();
solve(); return 0;
}
Codeforces Round #469 (Div. 2) E. Data Center Maintenance的更多相关文章
- Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路
Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xx ...
- Codeforces Round #469 (Div. 2)
Codeforces Round #469 (Div. 2) 难得的下午场,又掉分了.... Problem A: 怎么暴力怎么写. #include<bits/stdc++.h> #de ...
- Codeforces Round #469 Div. 2 A B C D E
A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...
- Codeforces Round #469 Div. 2题解
A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...
- 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)C. Zebras(思维+模拟)
C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standa ...
- Codeforces Round #469 (Div. 2) F. Curfew
贪心 题目大意,有2个宿管分别从1和n开始检查房间,记录人数不为n的房间个数,然后锁住房间. 没有被锁的房间中的学生可以选择藏在床底,留在原地,或者转移(最远转移d个房间) 然后抄了网上大神的代码 ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)
剧毒比赛,至少涨了分对吧.: ( [A]Left-handers, Right-handers and Ambidexters 题意: 有\(l\)个右撇子,\(r\)个左撇子,\(a\)个双手都惯用 ...
随机推荐
- underscore.js 分析 第二天
Underscore源码中有这么句obj.length === +obj.length意思是typeof obj.length == number,即检测obj的长度是否是数字我的理解:这么写是来检测 ...
- 初识c++模板元编程
模板元编程(Template metaprogramming,简称TMP)是编译器内执行的程序,编译器读入template,编译输出的结果再与其他源码一起经过普通编译过程生成目标文件.通俗来说,普通运 ...
- 正式放弃Edge,重新拥抱Chrome
从Edge还叫斯巴达的时候我就开始用了,本来对浏览器的要求也没多高,能够打开多个选项卡,稳定,支持最新的规范就好了. 但是Edge真的是越来越让我失望了,卡死问题越来越多,崩溃越来越频繁,我也快奔溃了 ...
- Vuejs 实现简易 todoList 功能 与 组件
todoList 结合之前 Vuejs 基础与语法 使用 v-model 双向绑定 input 输入内容与数据 data 使用 @click 和 methods 关联事件 使用 v-for 进行数据循 ...
- UVa 455 - Periodic Strings - ( C++ ) - 解题报告
1.题目大意 求一个长度不超过80的字符串的最小周期. 2.思路 非常简单,基本就是根据周期的定义做出来的,几乎不需要过脑. 3.应该注意的地方 (1) 最后输出的方式要注意,不然很容易就PE了.不过 ...
- leetcode个人题解——#17 Letter Combinations of a Phone Number
思路:用深搜遍历九宫格字符串,一开始做的时候发生了引用指向空地址的问题,后来发现是vector不能直接=赋值. class Solution { public: int len; ]={"a ...
- Linux 150命令之 文件和目录操作命令 ls
文件和目录操作命令 ls 查看文件和目录查看显示详信息 ls 工具的参数 ls -l 查看文件详细信息 ls -h 查看文件的大小 ls -ld 只查看目录信息 ls –F 给不同文件加上不同标记 l ...
- 环境变量PATH
一.举例 我在用户主文件夹执行命令“ls”,会在屏幕显示该文件夹下的所有文件.然而,ls的完整文件名为“/bin/ls”,按道理我不在/bin下要想执行ls命令必须输入“/bin/ls”,但我仅仅需要 ...
- Android中的回调Callback
回调就是外部设置一个方法给一个对象, 这个对象可以执行外部设置的方法, 通常这个方法是定义在接口中的抽象方法, 外部设置的时候直接设置这个接口对象即可. 例如给安卓添加按钮点击事件, 我们创建了OnC ...
- iOS开发解决页面滑动返回跟scrollView左右划冲突
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithG ...