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的更多相关文章

  1. 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 ...

  2. Codeforces Round #469 (Div. 2)

    Codeforces Round #469 (Div. 2) 难得的下午场,又掉分了.... Problem A: 怎么暴力怎么写. #include<bits/stdc++.h> #de ...

  3. Codeforces Round #469 Div. 2 A B C D E

    A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...

  4. Codeforces Round #469 Div. 2题解

    A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...

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

  6. Codeforces Round #469 (Div. 2)C. Zebras(思维+模拟)

    C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standa ...

  7. Codeforces Round #469 (Div. 2) F. Curfew

    贪心 题目大意,有2个宿管分别从1和n开始检查房间,记录人数不为n的房间个数,然后锁住房间. 没有被锁的房间中的学生可以选择藏在床底,留在原地,或者转移(最远转移d个房间)   然后抄了网上大神的代码 ...

  8. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  9. 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)

    剧毒比赛,至少涨了分对吧.: ( [A]Left-handers, Right-handers and Ambidexters 题意: 有\(l\)个右撇子,\(r\)个左撇子,\(a\)个双手都惯用 ...

随机推荐

  1. Mysql忘记密码处理办法

    找回密码的步骤如下: 1.停止mysql服务器 sudo /opt/lampp/lampp stopmysql 2.使用`--skip-grant-tables' 参数来启动 mysqld sudo ...

  2. CC3200-LAUNCHXL仿真器驱动异常(未完成)

    1. 测试中发现,跳线帽J2和J3连接的情况下,驱动不正常如图2,不连接的情况下,驱动正常,VCC_LDO_3V3给仿真器FT2232供电,VCC_BRD这个电源很奇怪,用途不清晰,VBAT_CC是给 ...

  3. MySQL高级-MySQL安装

    1.mysql安装 检查系统是否安装过mysql 查询命令:rpm -qa|grep -i mysql 删除命令:rpm -e RPM软件包名(该名字是上一个命令查出来的名字) 安装命令:rpm -i ...

  4. 探索 Flask

    探索 Flask 探索 Flask 是一本关于使用 Flask 开发 Web 应用程序的最佳实践和模式的书籍.这本书是由 426 名赞助人 在 Kickstarter 上 于 2013 年 7 月资助 ...

  5. JAVA FILE.renameTo跨文件系统移动文件失败

    遇到了FILE.renameTo跨文件系统移动文件失败的问题,应使用FILES.move()接口或在同一文件系统移动文件. FILE.renameTo接口说明: public boolean rena ...

  6. 「题目代码」P1060~P1065(Java)

    P1060 谭浩强C语言(第三版)习题7.5 注意行末空格. import java.util.*; import java.io.*; import java.math.*; import java ...

  7. Selenium(Python) ddt数据驱动

    首先, 添加ddt模块: import unittestfrom time import sleep from ddt import ddt, data, unpack# 导入ddt模块from se ...

  8. selenium,unittest——驾照科目一网上答题自动化

    需求很简单,所有题目全选A,然后点提交出分,校验是否到达出分这步 遇到的坑有这几个,一个是assertIn哪个是校验哪个是文本要分清,还有code的编码统一到Unicode,最后就是xpath定位各个 ...

  9. Java JDK5.0新特性

    JDK5.0新特性 虽然JDK已经到了1.8 但是1.5(5.0)的变化是最大的 1. 增强for循环 foreach语句 foreach简化了迭代器 作用: 对存储对象的容器进行迭代 (数组, co ...

  10. Siki_Unity_1-8_使用Unity开发2D游戏_PongGame

    Unity 1-8 使用Unity开发2D游戏 PongGame 任务1:演示 http://pan.baidu.com/s/1pKUHsev; up2i 任务2:案例介绍 创建PongGame,注意 ...