555E Case of Computer Network
分析
一个连通块内的肯定不影响
于是我们先缩点
之后对于每个路径
向上向下分别开一个差分数组
如果两个数组同时有值则不合法
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,q,bl[],s[],t[],dfn[],low[],is[];
int cnt,tot,sum,head[],nxt[],to[],ano[];
int d1[],d2[],dep[],pr[][];
int f[],vis[],vis2[];
vector<int>v[];
stack<int>a;
inline int sf(int x){return f[x]==x?x:f[x]=sf(f[x]);}
inline void add(int x,int y){
nxt[++tot]=head[x],head[x]=tot,to[tot]=y,ano[tot]=tot+;
nxt[++tot]=head[y],head[y]=tot,to[tot]=x,ano[tot]=tot-;
}
inline void tarjan(int x,int id){
dfn[x]=low[x]=++cnt;
a.push(x),is[x]=;
for(int i=head[x];i;i=nxt[i])
if(i!=ano[id]){
if(!dfn[to[i]]){
tarjan(to[i],i);
low[x]=min(low[x],low[to[i]]);
}else if(is[to[i]]){
low[x]=min(low[x],dfn[to[i]]);
}
}
if(low[x]==dfn[x]){
sum++;
while(){
int u=a.top();
a.pop(),is[u]=;
bl[u]=sum;
if(u==x)break;
}
}
}
inline void dfs(int x,int fa){
vis2[x]=;
pr[x][]=fa;
dep[x]=dep[fa]+;
for(int i=;i<v[x].size();i++)
if(v[x][i]!=fa)dfs(v[x][i],x);
}
inline int lca(int x,int y){
if(dep[x]<dep[y])swap(x,y);
int i,j,k,len=dep[x]-dep[y];
for(i=;i<=;i++)
if((<<i)&len)x=pr[x][i];
if(x==y)return x;
for(i=;i>=;i--)
if(pr[x][i]!=pr[y][i])
x=pr[x][i],y=pr[y][i];
return pr[x][];
}
inline void dfs2(int x,int fa){
vis[x]=;
for(int i=;i<v[x].size();i++)
if(v[x][i]!=fa)dfs2(v[x][i],x),d1[x]+=d1[v[x][i]],d2[x]+=d2[v[x][i]];
if(d1[x]>&&d2[x]>){
puts("No");
exit();
}
}
int main(){
int i,j,k;
scanf("%d%d%d",&n,&m,&q);
for(i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
add(x,y);
if(sf(x)!=sf(y))f[sf(x)]=sf(y);
}
for(i=;i<=q;i++)scanf("%d%d",&s[i],&t[i]);
for(i=;i<=q;i++)if(sf(s[i])!=sf(t[i])){puts("No");return ;}
for(i=;i<=n;i++)if(!dfn[i])tarjan(i,);
for(i=;i<=n;i++)
for(j=head[i];j;j=nxt[j])
if(bl[i]!=bl[to[j]])v[bl[i]].push_back(bl[to[j]]);
for(i=;i<=sum;i++)if(!vis2[i])dfs(i,);
for(i=;i<=;i++)
for(j=;j<=sum;j++)
pr[j][i]=pr[pr[j][i-]][i-];
for(i=;i<=q;i++){
if(bl[s[i]]==bl[t[i]])continue;
int x=bl[s[i]],y=bl[t[i]],z=lca(x,y);
d1[x]++,d1[z]--;
d2[y]++,d2[z]--;
}
for(i=;i<=sum;i++)if(!vis[i])dfs2(i,);
puts("Yes");
return ;
}
555E Case of Computer Network的更多相关文章
- [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)
[Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...
- (中等) CF 555E Case of Computer Network,双连通+树。
Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible a ...
- 「CF555E」 Case of Computer Network
「CF555E」 Case of Computer Network 传送门 又是给边定向的题目(马上想到欧拉回路) 然而这个题没有对度数的限制,你想歪了. 然后又开始想一个类似于匈牙利的算法:我先跑, ...
- Solution -「CF 555E」Case of Computer Network
\(\mathcal{Description}\) Link. 给定 \(n\) 个点 \(m\) 条边的无向图,判断是否有给每条边定向的方案,使得 \(q\) 组有序点对 \((s,t)\) ...
- CF555E Case of Computer Network
题面:https://www.luogu.com.cn/problem/CF555E 题意:给定一张\(n\)个点\(m\)条边的无向图. 给定\(q\)组有向点对\((s,t)\). 询问是否存在使 ...
- 题解 CF555E Case of Computer Network
题目传送门 题目大意 给出一个\(n\)个点\(m\)条边的无向图,有\(q\)次有向点对\((s,t)\),问是否存在一种方法定向每条边使得每个点对可以\(s\to t\). \(n,m,q\le ...
- codeforces GYM 100114 J. Computer Network 无相图缩点+树的直径
题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” ...
- codeforces GYM 100114 J. Computer Network tarjan 树的直径 缩点
J. Computer Network Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Des ...
- SGU 149. Computer Network( 树形dp )
题目大意:给N个点,求每个点的与其他点距离最大值 很经典的树形dp...很久前就想写来着...看了陈老师的code才会的...mx[x][0], mx[x][1]分别表示x点子树里最长的2个距离, d ...
随机推荐
- 定义一个接口CanFly,描述会飞的方法public void fly();
1.使用类与接口的知识完成如下要求:(1)定义一个接口CanFly,描述会飞的方法public void fly();(2)分别定义类飞机和鸟,实现CanFly接口.(3)定义一个测试类,测试飞机和鸟 ...
- 如何写一个 Burp 插件
Burp 是 Web 安全测试中不可或缺的神器.每一个师傅的电脑里面应该都有一个 Burp.同时 Burp 和很多其他神器一样,它也支持插件.但是目前总体来说网上 Burp 插件开发的资料不是特别特别 ...
- 367-基于zynq XC7Z100 FMC接口通用计算平台
基于zynq XC7Z100 FMC接口通用计算平台 一.板卡概述 本板卡基于Xilinx公司的FPGA XC7Z100 FFG 9000 芯片, 该平台为设计和验证应用程序提供了一个完整的开发平台. ...
- 五、WebSocket 链接
一.前端代码: <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml& ...
- Chrome,firefox解除阻止视频自动播放
Firefox 66 将阻止自动播放音频和视频 PingWest品玩2月5日报道,从发布适用于桌面的 Firefox 66 和 Firefox for Android 开始,Firefox 将默认阻止 ...
- CF 1272F Two Bracket Sequences (括号dp)
题目地址 洛谷CF1272F Solution 首先题目中有两个括号串 \(s\) 和 \(t\) ,考虑先设计两维表示 \(s\) 匹配到的位置和 \(t\) 匹配到的位置. 接着根据 括号dp的一 ...
- Prism MVVM使用WPF的DataGrid控件
此项目源码下载地址:https://github.com/lizhiqiang0204/PrismDataGird01 运行效果如下 前端代码如下 <Window x:Class="V ...
- 【NOIP2016提高A组模拟9.17】小a的强迫症
题目 分析 题目要求第i种颜色的最后一个珠子要在第i+1种颜色的最后一个珠子之前, 那么我们从小到大枚举做到第i种,把第i种的最后一颗珠子取出,将剩下的\(num(i)-1\)个珠子插入已排好的前i- ...
- VUE实现限制输入框最多输入15个中文,或者30个英文
vue项目,输入框限制输入15个中文,或者30个英文 <input type="text" v-model="groupName" class=" ...
- firebird默认字符在lazarus下乱码问题
firebird3数据表中,如果字段是varchar时, delphiXE的firedac在读取时正常,但lazarus中读取时会显示乱码. 经过测试发现,如果lazarus显示正常的话,必须在建表时 ...