比赛 “Asm.Def战记之夏威夷”杯 评测结果 AWWWWWWWWA
题目名称 Asm.Def的病毒 最终得分 20
用户昵称 dydxh 运行时间 0.036 s
代码语言 C++ 内存使用 0.33 MiB
提交时间 2015-11-06 10:41:47
显示代码纯文本
  1. /*
  2. Problem:cogs2100;
  3. Language:c++;
  4. by dydxh;
  5. 2015.11.06;
  6. */
  7. #include<iostream>
  8. #include<cstdio>
  9. #include<set>
  10. #include<map>
  11. #include<queue>
  12. #include<algorithm>
  13. #include<cstring>
  14. #include<cmath>
  15. #include<utility>
  16. #include<ctime>
  17. #include<cstdlib>
  18. #include<string>
  19. #define ll long long
  20. #define ull unsigned long long
  21. using namespace std;
  22. const int maxn=1005;
  23. const int oo=2000000000;
  24. int n,Q,len,y;
  25. int linkk[maxn];
  26. bool flag[maxn];
  27. bool Arr;
  28. struct edge{
  29. int y,next;
  30. }e[maxn<<1];
  31. inline int read(){
  32. int x=0;bool flag=0;char ch=getchar();
  33. while(ch>'9' || ch<'0') {if(ch=='-') flag=1;ch=getchar();}
  34. while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
  35. return flag?-x:x;
  36. }
  37. void insert(int a,int b){
  38. e[++len].next=linkk[a];
  39. linkk[a]=len;
  40. e[len].y=b;
  41. e[++len].next=linkk[b];
  42. linkk[b]=len;
  43. e[len].y=a;
  44. }
  45. void Dfs(int x,int Father){
  46. if(x==y){
  47. Arr=true;
  48. return ;
  49. }
  50. for(int i=linkk[x];i;i=e[i].next){
  51. int tn=e[i].y;
  52. if(tn==Father || flag[tn]) continue;
  53. Dfs(tn,x);
  54. if(Arr){
  55. flag[tn]=true;
  56. return ;
  57. }
  58. }
  59. }
  60. int main(){
  61. freopen("asm_virus.in","r",stdin);
  62. freopen("asm_virus.out","w",stdout);
  63. n=read(),Q=read();
  64. for(int i=1;i<n;i++)
  65. insert(read(),read());
  66. while(Q--){
  67. memset(flag,0,sizeof(flag));
  68. int x=read();y=read();
  69. Arr=false;flag[x]=true;
  70. Dfs(x,0);
  71. x=read(),y=read();
  72. Arr=false;
  73. Dfs(x,0);
  74. if(Arr) printf("NO\n");
  75. else printf("YES\n");
  76. }
  77. //cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
  78. return 0;
  79. }