QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602588 | #8720. BFS 序 0 | UESTC_OldEastWest# | WA | 46ms | 16712kb | C++17 | 969b | 2024-10-01 10:58:26 | 2024-10-01 10:58:27 |
Judging History
answer
#include <bits/stdc++.h>
void charming() {
int n; std::cin >> n;
std::vector<int> fa(n), dep(n);
std::vector<std::vector<int> > G(n);
for (int i = 1; i < n; ++i) {
std::cin >> fa[i], --fa[i];
G[fa[i]].emplace_back(i);
}
std::vector<int> que(1, 0);
for (int i = 0, u; i < n; ++i) {
u = que[i];
for (int v : G[u]) {
que.emplace_back(v);
dep[v] = dep[u] + 1;
}
}
int q; std::cin >> q;
for (int i = 0, m; i < q; ++i) {
std::cin >> m;
std::vector<int> vec(m);
for (int j = 0; j < m; ++j) std::cin >> vec[j], --vec[j];
bool ok = true;
for (int j = 1; j < m; ++j) {
if (dep[vec[j]] < dep[vec[j - 1]]) {
ok = false;
break;
}
}
if (ok) std::cout << "Yes\n";
else std::cout << "No\n";
}
}
signed main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
charming();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
6 1 1 3 2 4 10 4 3 6 2 5 1 4 3 2 4 5 5 2 5 4 6 3 3 1 4 2 3 5 6 3 5 4 5 2 6 1 4 4 3 2 5 4 4 6 2 3 3 3 2 6
output:
No Yes Yes No No No No No No Yes
result:
ok 10 token(s): yes count is 3, no count is 7
Test #2:
score: -100
Wrong Answer
time: 46ms
memory: 16712kb
input:
300000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong answer expected NO, found YES [1st token]