CF949 C Data Center Maintenance——边双连通分量
题目:http://codeforces.com/contest/949/problem/C
把一个点指向修改它会影响到的点就可以做了;
有取模,所以多出一些要注意的地方,首先是可能出现环,所以需要 tarjan 求边双;
其次,边集数组的大小应该开成两倍,因为取模可能导致一对 ci 互相连边;
然后找出不影响别的点的、最小的边双,输出即可;
而我竟然把 tarjan 都少写了一个 top-- !真是对自己无语了...
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int const maxn=1e5+;
int n,m,h,a[maxn],hd[maxn],cr,ct,col[maxn],sta[maxn],top,dfn[maxn],low[maxn],tim,deg[maxn];
bool vis[maxn];
vector<int>scc[maxn];
struct N{
int to,nxt;
N(int t=,int n=):to(t),nxt(n) {}
}ed[maxn<<];
void add(int x,int y){ed[++ct]=N(y,hd[x]); hd[x]=ct;}
void tarjan(int x)
{
dfn[x]=low[x]=++tim; sta[++top]=x; vis[x]=;
for(register int i=hd[x];i;i=ed[i].nxt)
{
int u=ed[i].to;
if(!dfn[u])
{
tarjan(u); low[x]=min(low[x],low[u]);
}
else if(vis[x])low[x]=min(low[x],dfn[u]);
}
if(low[x]==dfn[x])
{
cr++;
while(sta[top]!=x)
{
int y=sta[top]; top--;
vis[y]=; col[y]=cr;
scc[cr].push_back(y);
}
top--;//!
vis[x]=; col[x]=cr; scc[cr].push_back(x);
}
}
int main()
{
scanf("%d%d%d",&n,&m,&h);
for(register int i=;i<=n;i++)scanf("%d",&a[i]);
for(register int i=,x,y;i<=m;i++)
{
scanf("%d%d",&x,&y);
if((a[x]+)%h==a[y])add(x,y);
if((a[y]+)%h==a[x])add(y,x);
}
for(register int i=;i<=n;i++)
if(!dfn[i])tarjan(i);
for(register int i=;i<=n;i++)
for(register int j=hd[i];j;j=ed[j].nxt)
{
int u=ed[j].to;
if(col[i]!=col[u])deg[col[i]]++;
}
int mn=0x3f3f3f3f,tag;
for(register int i=;i<=cr;i++)
if(!deg[i]&&scc[i].size()<mn)mn=scc[i].size(),tag=i;
printf("%d\n",scc[tag].size());
for(register int j=;j<scc[tag].size();j++)
printf("%d ",scc[tag][j]);
return ;
}
CF949 C 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$后,所有条件成立(数据保证有解). 题解:对于每个条 ...
- cf950e Data Center Maintenance
若推迟 \(u\) 必推迟 \(v\),则连边 <\(u,v\)>. 求强联通分量后缩点,答案显然是出度为 \(0\) 且 size 最小的 scc. #include <iostr ...
- Data Center Maintenance CodeForces - 950E
http://codeforces.com/contest/950/problem/E 贴一份板子 #include<cstdio> #include<vector> #inc ...
随机推荐
- Robot Framework(九) 执行测试用例——基本用法
3.1基本用法 Robot Framework测试用例从命令行执行,默认情况下,最终结果是XML格式的输出文件和HTML 报告和日志.执行后,可以组合输出文件,然后使用rebot工具进行后处理. 3. ...
- 查询条件中,不进sql语句 也不进后台bug
前端代码:本来代码中少写了value="1",后来加上value值之后,可以正常进方法 <div class="row"> <label cl ...
- react 导航切换
<ul class="nav"> <li onClick={() => this.changeFontColor(0)} className={`${0 = ...
- Android 7.0系统代码调用安装apk时报错FileUriExposedException完美解决
项目更新遇到问题 Android项目开发中经常遇到下载更新的需求,以前调用系统安装器执行安装操作代码如下: Intent intent = new Intent(); intent.setActi ...
- P1541 乌龟棋 题解(洛谷,动态规划递推)
题目:P1541 乌龟棋 感谢大神的题解(他的写的特别好) 写一下我对他的代码的理解吧(哎,蒟蒻就这能这样...) 代码: #include<bits/stdc++.h> #define ...
- cout 按进制数出
头文件: #include<iostream> #include<iomanip> //setbase() #include<bitset> //bitset< ...
- UVA-1589 象棋(模拟)
题目:(传送门) 给出一个象棋的残局,下一步是黑棋走,判断黑棋是不是被将死. 思路: 读完这个题,知道是一个模拟题,然后想到用两个二维数组来模拟棋盘,一个(mp数组)用来存残局,一个(res数组)用来 ...
- Python学习第二阶段Day2(json/pickle)、 shelve、xml、PyYAML、configparser、hashlib模块
1.json/pickle 略. 2.shelve模块 import shelve # shelve 以key value的形式序列化,value为对象 class Foo(object): de ...
- iframe使用大全
<iframe src=”you page’s url” width=”100″ height=”30″ frameborder=”no” border=”0″ marginwidth=”0″ ...
- linux 安装 phpstorm 并破解
下载官方软件linux版phpstrom, 貌似很卡要FQ. 我下载我的百度网盘备用了.解压目录, mv 到/opt/ 下 cd进 bin目录下chmod 777 phpstorm.sh执行 ./ ...