比赛 |
“Asm.Def战记之夏威夷”杯 |
评测结果 |
AWWWWWWWWA |
题目名称 |
Asm.Def的病毒 |
最终得分 |
20 |
用户昵称 |
dydxh |
运行时间 |
0.036 s |
代码语言 |
C++ |
内存使用 |
0.33 MiB |
提交时间 |
2015-11-06 10:41:47 |
显示代码纯文本
/*
Problem:cogs2100;
Language:c++;
by dydxh;
2015.11.06;
*/
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<utility>
#include<ctime>
#include<cstdlib>
#include<string>
#define ll long long
#define ull unsigned long long
using namespace std;
const int maxn=1005;
const int oo=2000000000;
int n,Q,len,y;
int linkk[maxn];
bool flag[maxn];
bool Arr;
struct edge{
int y,next;
}e[maxn<<1];
inline int read(){
int x=0;bool flag=0;char ch=getchar();
while(ch>'9' || ch<'0') {if(ch=='-') flag=1;ch=getchar();}
while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
return flag?-x:x;
}
void insert(int a,int b){
e[++len].next=linkk[a];
linkk[a]=len;
e[len].y=b;
e[++len].next=linkk[b];
linkk[b]=len;
e[len].y=a;
}
void Dfs(int x,int Father){
if(x==y){
Arr=true;
return ;
}
for(int i=linkk[x];i;i=e[i].next){
int tn=e[i].y;
if(tn==Father || flag[tn]) continue;
Dfs(tn,x);
if(Arr){
flag[tn]=true;
return ;
}
}
}
int main(){
freopen("asm_virus.in","r",stdin);
freopen("asm_virus.out","w",stdout);
n=read(),Q=read();
for(int i=1;i<n;i++)
insert(read(),read());
while(Q--){
memset(flag,0,sizeof(flag));
int x=read();y=read();
Arr=false;flag[x]=true;
Dfs(x,0);
x=read(),y=read();
Arr=false;
Dfs(x,0);
if(Arr) printf("NO\n");
else printf("YES\n");
}
//cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
return 0;
}