QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#602588#8720. BFS 序 0UESTC_OldEastWest#WA 46ms16712kbC++17969b2024-10-01 10:58:262024-10-01 10:58:27

Judging History

你现在查看的是最新测评结果

  • [2024-10-01 10:58:27]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:16712kb
  • [2024-10-01 10:58:26]
  • 提交

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;
}

詳細信息

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]