Case of Computer Network

CodeForces - 555E

Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible attack by hackers on a major computer network.

In this network are n vertices, some pairs of vertices are connected by m undirected channels. It is planned to transfer q important messages via this network, the i-th of which must be sent from vertex si to vertex di via one or more channels, perhaps through some intermediate vertices.

To protect against attacks a special algorithm was developed. Unfortunately it can be applied only to the network containing directed channels. Therefore, as new channels can't be created, it was decided for each of the existing undirected channels to enable them to transmit data only in one of the two directions.

Your task is to determine whether it is possible so to choose the direction for each channel so that each of the q messages could be successfully transmitted.

Input

The first line contains three integers nm and q (1 ≤ n, m, q ≤ 2·105) — the number of nodes, channels and important messages.

Next m lines contain two integers each, vi and ui (1 ≤ vi, ui ≤ nvi ≠ ui), that means that between nodes vi and ui is a channel. Between a pair of nodes can exist more than one channel.

Next q lines contain two integers si and di (1 ≤ si, di ≤ nsi ≠ di) — the numbers of the nodes of the source and destination of the corresponding message.

It is not guaranteed that in it initially possible to transmit all the messages.

Output

If a solution exists, print on a single line "Yes" (without the quotes). Otherwise, print "No" (without the quotes).

Examples

Input
4 4 2
1 2
1 3
2 3
3 4
1 3
4 2
Output
Yes
Input
3 2 2
1 2
3 2
1 3
2 1
Output
No
Input
3 3 2
1 2
1 2
3 2
1 3
2 1
Output
Yes

Note

In the first sample test you can assign directions, for example, as follows: 1 → 2, 1 → 3, 3 → 2, 4 → 3. Then the path for for the first message will be 1 → 3, and for the second one — 4 → 3 → 2.

In the third sample test you can assign directions, for example, as follows: 1 → 2, 2 → 1, 2 → 3. Then the path for the first message will be 1 → 2 → 3, and for the second one — 2 → 1.

简要题意:给出一个无向图,给出q个询问S,T表示从S走到T。
问能否给这张图的边定向,使得满足q个询问

sol:因为是无向图,所以在同一个强联通分量中是两两可以随意到达,然后可以搞成一棵树,树上可以差分一下,两个数组p0,p1,S位置p0++,T位置p1++,Lca处p0--,p1--,看看是否有一个点既有p0又有p1就No了

/*
¼òÒªÌâÒ⣺¸ø³öÒ»¸öÎÞÏòͼ£¬¸ø³öq¸öѯÎÊS£¬T±íʾ´ÓS×ßµ½T¡£
ÎÊÄÜ·ñ¸øÕâÕÅͼµÄ±ß¶¨Ïò£¬Ê¹µÃÂú×ãq¸öѯÎÊ
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=; bool f=; char ch=' ';
while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
while(isdigit(ch)) {s=(s<<)+(s<<)+(ch^); ch=getchar();}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<) {putchar('-'); x=-x;}
if(x<) {putchar(x+''); return;}
write(x/); putchar((x%)+'');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=,M=;
int n,m,Q;
int tot=,Next[M],to[M],head[N];
struct Ques{int S,T;}qq[N];
inline void Link(int x,int y)
{
Next[++tot]=head[x]; to[tot]=y; head[x]=tot;
}
int cnt=,dfn[N],low[N],top=,Sta[N],now=,Bel[N];
bool ins[N];
inline void tarjan(int x,int fat)
{
int i;
bool bo=;
dfn[x]=low[x]=++cnt; Sta[++top]=x; ins[x]=;
for(i=head[x];i;i=Next[i])
{
if(to[i]==fat&&bo) {bo=; continue;}
if(!dfn[to[i]])
{
tarjan(to[i],x); low[x]=min(low[x],low[to[i]]);
}
else if(ins[to[i]]) low[x]=min(low[x],dfn[to[i]]);
}
if(dfn[x]==low[x])
{
int oo=; now++;
while(oo!=x)
{
oo=Sta[top--]; Bel[oo]=now; ins[oo]=;
}
}
}
vector<int>E[N];
#define PB push_back
int fa[N];
inline int gf(int x)
{
return (fa[x]==x)?(x):(fa[x]=gf(fa[x]));
}
int Dep[N],ff[N][];
inline void dfs(int x,int fat)
{
int i;
for(i=;i<E[x].size();i++) if(E[x][i]!=fat)
{
Dep[E[x][i]]=Dep[x]+; ff[E[x][i]][]=x; dfs(E[x][i],x);
}
}
inline int ask_lca(int x,int y)
{
int i;
if(Dep[x]<Dep[y]) swap(x,y);
for(i=;~i;i--) if(Dep[ff[x][i]]>=Dep[y]) x=ff[x][i];
if(x==y) return x;
for(i=;~i;i--) if(ff[x][i]!=ff[y][i]) x=ff[x][i],y=ff[y][i];
return ff[x][];
}
int path[N][];
bool Vis[N];
inline void dfss(int x,int fat)
{
int i;
Vis[x]=;
for(i=;i<E[x].size();i++)
{
int V=E[x][i]; if(V==fat) continue;
dfss(V,x);
path[x][]+=path[V][]; path[x][]+=path[V][];
}
}
int main()
{
// freopen("codeforces555E.in","r",stdin);
int i,j,x,y;
R(n); R(m); R(Q);
for(i=;i<=m;i++)
{
R(x); R(y); Link(x,y); Link(y,x);
}
for(i=;i<=Q;i++) {R(qq[i].S); R(qq[i].T);}
for(i=;i<=n;i++) if(!dfn[i]) tarjan(i,);
// cout<<"now="<<now<<endl;
// for(i=1;i<=n;i++) cout<<i<<' '<<Bel[i]<<endl;
// puts("");
for(i=;i<=now;i++) fa[i]=i;
for(i=;i<=n;i++)
{
for(j=head[i];j;j=Next[j])
{
int o1=gf(Bel[i]),o2=gf(Bel[to[j]]);
if(o1==o2) continue;
E[Bel[i]].PB(Bel[to[j]]); E[Bel[to[j]]].PB(Bel[i]); fa[o1]=o2;
}
}
for(i=;i<=now;i++) if(!Dep[i]) {Dep[i]=; dfs(i,);}
// for(i=1;i<=now;i++) cout<<i<<' '<<Dep[i]<<endl;
// puts("");
for(i=;i<=;i++) for(j=;j<=now;j++) ff[j][i]=ff[ff[j][i-]][i-];
// for(i=1;i<=now;i++) cout<<i<<' '<<ff[i][0]<<endl;
// puts("");
for(i=;i<=Q;i++)
{
int S=Bel[qq[i].S],T=Bel[qq[i].T];
// cout<<S<<' '<<gf(S)<<' '<<T<<' '<<gf(T)<<endl;
if(gf(S)!=gf(T)) return puts("No"),;
int lca=ask_lca(S,T);
// cout<<S<<' '<<T<<' '<<"lca="<<lca<<endl;
path[S][]++; path[lca][]--; path[T][]++; path[lca][]--;
}
// puts("");
// for(i=1;i<=now;i++) cout<<i<<' '<<path[i][0]<<' '<<path[i][1]<<endl;
for(i=;i<=now;i++) if(!Vis[i]) dfss(i,);
for(i=;i<=Q;i++)
{
int S=Bel[qq[i].S],T=Bel[qq[i].T]; if(S==T) continue;
if((path[S][]&&path[S][])||(path[T][]&&path[T][])) return puts("No"),;
}
puts("Yes");
return ;
}
/*
Input
4 4 2
1 2
1 3
2 3
3 4
1 3
4 2
Output
Yes Input
3 2 2
1 2
3 2
1 3
2 1
Output
No Input
3 3 2
1 2
1 2
3 2
1 3
2 1
Output
Yes
*/

codeforces555E的更多相关文章

随机推荐

  1. 160个creakme(八)

    peid跑一下,没有壳 就是输入一个码 直接运行一下,出现错误提示 找字符串能找到代码位置 然后看一下401E43的引用,好像跳转指令后面就是注册成功相关字符串 然后nop掉这条指令,发现可以运行出正 ...

  2. LibSVM格式简介

    对于训练或预测,XGBoost采用如下格式的实例文件: train.txt 1 101:1.2 102:0.03 0 1:2.1 10001:300 10002:400 0 0:1.3 1:0.3 1 ...

  3. javascript之取余数、去商、天花板取整、地板取整

    demo1: console.log('//求余数'); //求余数 console.log(5 % 4); console.log(6 % 4); //求商 console.log('//求商'); ...

  4. 论文阅读:《Bag of Tricks for Efficient Text Classification》

    论文阅读:<Bag of Tricks for Efficient Text Classification> 2018-04-25 11:22:29 卓寿杰_SoulJoy 阅读数 954 ...

  5. mysql 5.7.19安装

    从mysql官网下载的mysql5.7.19免安装版, 安装时出现问题,mysql总是启动不起来,在网上查了下资料,做个记录: .将mysql解压到指定的文件夹 .以管理员身份运行cmd .定位到my ...

  6. [JZOJ3521]道路覆盖--状压DP

    题目链接 略略略 分析 首先一看到使得最低的高度最高就想到了二分,于是就转化成了一个是否可行的问题 发现这个\(k\)都很小,考虑使用状态压缩DP 但是我一开始发现似乎并不好设计状态...如果这个\( ...

  7. C++ 构造函数后面的冒号的作用

    其实冒号后的内容是初始化成员列表,一般有三种情况:     1.对含有对象成员的对象进行初始化,例如,     类line有两个私有对象成员startpoint.endpoint,line的构造函数写 ...

  8. java中long类型转换为int类型

    由int类型转换为long类型是向上转换,可以直接进行隐式转换,但由long类型转换为int类型是向下转换,可能会出现数据溢出情况: 主要以下几种转换方法,供参考: 一.强制类型转换 [java] l ...

  9. XML模块与类的定义

    xml模块 xml介绍: --XML 全称  可扩展标记语言 --<tag></tag>  双标签   标签中间可以加入文本信息 --<tag/>单标签  没有文本 ...

  10. JS-闭包练习

    首先,第一个输出,因为前置运算,i要先参与输出,然后再自增,所以输出为0 第二个输出,因为f1和f2是不同的函数,不共享i变量,所以输出也为0 第三个输出,因为是f1,共享i,所以i加了1,输出为1 ...