分析

一个连通块内的肯定不影响

于是我们先缩点

之后对于每个路径

向上向下分别开一个差分数组

如果两个数组同时有值则不合法

代码

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

  1. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

  2. (中等) CF 555E Case of Computer Network,双连通+树。

    Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible a ...

  3. 「CF555E」 Case of Computer Network

    「CF555E」 Case of Computer Network 传送门 又是给边定向的题目(马上想到欧拉回路) 然而这个题没有对度数的限制,你想歪了. 然后又开始想一个类似于匈牙利的算法:我先跑, ...

  4. Solution -「CF 555E」Case of Computer Network

    \(\mathcal{Description}\)   Link.   给定 \(n\) 个点 \(m\) 条边的无向图,判断是否有给每条边定向的方案,使得 \(q\) 组有序点对 \((s,t)\) ...

  5. CF555E Case of Computer Network

    题面:https://www.luogu.com.cn/problem/CF555E 题意:给定一张\(n\)个点\(m\)条边的无向图. 给定\(q\)组有向点对\((s,t)\). 询问是否存在使 ...

  6. 题解 CF555E Case of Computer Network

    题目传送门 题目大意 给出一个\(n\)个点\(m\)条边的无向图,有\(q\)次有向点对\((s,t)\),问是否存在一种方法定向每条边使得每个点对可以\(s\to t\). \(n,m,q\le ...

  7. codeforces GYM 100114 J. Computer Network 无相图缩点+树的直径

    题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” ...

  8. codeforces GYM 100114 J. Computer Network tarjan 树的直径 缩点

    J. Computer Network Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Des ...

  9. SGU 149. Computer Network( 树形dp )

    题目大意:给N个点,求每个点的与其他点距离最大值 很经典的树形dp...很久前就想写来着...看了陈老师的code才会的...mx[x][0], mx[x][1]分别表示x点子树里最长的2个距离, d ...

随机推荐

  1. oracle常用函数(2)

    1) trunc函数,用于截断数字, 截断数字,用法为:trunc(n1,n2),n1表示要被截断的数字,n2表示要截断到那位,但是不会进行四舍五入. n2还可以表示负数,表示截断到小数点前,意思就是 ...

  2. fullpage实现(-)

    在线demo还没弄好,地址先给出来

  3. jsp-TagLib标签库

    <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ t ...

  4. Qualcomm_Mobile_OpenCL.pdf 翻译-3

    3 在骁龙上使用OpenCL 在今天安卓操作系统和IOT(Internet of Things)市场上,骁龙是性能最强的也是最被广泛使用的芯片.骁龙的手机平台将最好的组件组合在一起放到了单个芯片上,这 ...

  5. javase中的super、this和protected关键字

    关键字 this 记住一句话:this是指向对象本身的一个指针. 注意: this只能用于方法体内,且只能在非静态方法中,也就是说只有实例调用的方法中才能出现this,我们可以认为当new了一个实例后 ...

  6. Django学习系列5:为视图编写单元测试

    打开lists/tests.py编写 """向浏览器返回真正的HTML响应,添加一个新的测试方法""" from django.test i ...

  7. react-native启动时红屏报错:Unable to load script.Make sure you're either running a metro server or that ....

    一.报错信息内容 我是在Android Studio中运行启动react-native项目时报的这个错误 1.报错提示:Unable to load script.Make sure you're e ...

  8. ActiveMQ与Spring / SpringBoot 整合(四)

    1. 对 Spring 的整合 1.1 所需jar 包 <!-- activeMQ jms 的支持 --> <dependency> <groupId>org.sp ...

  9. Spring Boot 整合监听器

    Listener是servlet规范中定义的一种特殊类,用于监听servletContext.HttpSession和servletRequest等域对象的创建和销毁事件,监听域对象的属性发生修改的事 ...

  10. 通过shell监控网页是否正常,然后促发邮件告警

    最近在网上找了下通过shell编写一个脚本来监控网页是否正常,如果不正常则促发邮件告警,修复后有一个修复的通知邮件:但一直没有找到全面的,所以自己研究了下,写了一个linux对接邮箱和通过shell写 ...