比赛 |
“Asm.Def战记之夏威夷”杯 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Asm.Def的病毒 |
最终得分 |
100 |
用户昵称 |
---- |
运行时间 |
0.168 s |
代码语言 |
C++ |
内存使用 |
0.29 MiB |
提交时间 |
2015-11-06 09:04:50 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1033;;
vector<int> G[maxn];
int n, q;
bool dfs(int u, int fa, bool *wr, int tg)
{
if (u == tg) return wr[u] = true;
for (vector<int>::iterator p = G[u].begin(); p != G[u].end(); ++p)
if (*p != fa && dfs(*p, u, wr, tg)) { wr[u] = true; break; }
return wr[u];
}
int main()
{
freopen("asm_virus.in", "r", stdin);
#ifndef debug
freopen("asm_virus.out", "w", stdout);
#endif
scanf("%d%d", &n, &q);
for (int i = 1; i < n; ++i)
{
int u, v; scanf("%d%d", &u, &v);
G[u].push_back(v); G[v].push_back(u);
}
while (q --> 0)
{
int x, y, X, Y;
static bool ra[maxn], rb[maxn];
memset(ra, 0, sizeof(ra));
memset(rb, 0, sizeof(rb));
scanf("%d%d%d%d", &x, &y, &X, &Y);
dfs(x, 0, ra, y); dfs(X, 0, rb, Y);
bool flag = false;
for (int i = 1; i <= n; ++i) flag |= ra[i] && rb[i];
puts(flag ? "YES" : "NO");
}
}