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\)个双手都惯用 ...
随机推荐
- python之web架构
一.web架构简介 web.py是一个轻量级Python web框架,它简单而且功能强大.web.py是一个开源项目.该框架由已故美国作家.Reddit联合创始人.RSS规格合作创造者.著名计算机黑客 ...
- JDBC 工具类模板c3p0
JDBC 工具类模板 package com.itheima.sh.utils; import com.mchange.v2.c3p0.ComboPooledDataSource; import ja ...
- 金山注入浏览器默认开启上网导航 www.uu114.cn
金山注入浏览器默认开启上网导航 www.uu114.cn 今天突然发现我的电脑所有浏览器打开后,都会默认打开一个www.uu114.cn网站,chrome.firefox和IE都中招了.经过排查,发现 ...
- Appium(Python)测试混血App
Hybrid App(混合模式移动应用)是指介于web-app.native-app这两者之间的app兼具Native App良好用户交互体验的优势和Web App跨平台开发的优势 HybridApp ...
- 谁说接口不能有代码?—— Kotlin接口简介(KAD 26)
作者:Antonio Leiva 时间:Jun 6, 2017 原文链接:https://antonioleiva.com/interfaces-kotlin/ 与Java相比,Kotlin接口允许你 ...
- 【isJson( jsonObj )】判断是否是JSON实例
判断是否是JSON实例: 原型:isJson( jsonObj ) 说明:判断对象是否是JSON实例 返回:[true | false] 示例: <% Set jsonObj1 = toJson ...
- informix如何查询第一条记录
1.select first 1 * from shop; 正序查询第一条数据 2.select first 1 * from shop order by create_time desc; 按创建时 ...
- Django学习总结②----关系运算与F,Q关系
关联mysql步骤: 第一步:下载pymysql:pip install pymysql 第二步:在工程目录下的init文件下,将pymysql引入 import pymysql pymysql.in ...
- 【带 josn参数的测法】
遇到json 参数的情况这样写 ,否则就会报错 cod 415 nocookie post请求 ,","email":"beihe@163.com&quo ...
- 骰子涂色 (Cube painting,UVa 253)
题目描述:算法竞赛入门习题4-4 题目思路:1.旋转其中一个骰子进行匹配 2.进行遍历,如果匹配,就进行相对面的匹配 3.三个对立面都匹配即是一样等价的 //没有按照原题的输入输出 #include ...