QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602563#8720. BFS 序 0frs#WA 57ms15284kbC++141.2kb2024-10-01 10:46:542024-10-01 10:46:57

Judging History

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

  • [2024-10-01 10:46:57]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:15284kb
  • [2024-10-01 10:46:54]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int N = 3e5 + 5;
const int M = 5e5 + 5;

int n, qr, m, cnt[N], a[N];
vector<int> ve[N];

struct qnode{
    int id, d;
    qnode(int id1 = 0, int d1 = 0){
        id = id1;
        d = d1;
    }
}tp;
queue<qnode> q;

int main(){
    scanf("%d", &n);
    int u;
    for(int i = 2; i <= n; i++){
        scanf("%d", &u);
        ve[u].push_back(i);
    }
    q.push(qnode(1, 1));
    while(!q.empty()){
        tp = q.front();
        q.pop();
        cnt[tp.id] = tp.d;
        int sz = ve[tp.id].size();
        for(int i = 0; i < sz; i++){
            q.push(qnode(ve[tp.id][i], tp.d + 1));
        }
    }
    scanf("%d", &qr);
    while(qr--){
        scanf("%d", &m);
        for(int i = 1; i <= m; i++){
            scanf("%d", &a[i]);
        }
        bool flag = 1;
        for(int i = 2; i <= m; i++){
            if(cnt[a[i]] < cnt[a[i - 1]]){
                flag = 0;
                break;
            }
        }
        if(!flag) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11876kb

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: 57ms
memory: 15284kb

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]